Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- unordered_map<int, int> freq;
- int t, n, x;
- string s;
- cin >> t;
- for(int i=0; i<t; i++) {
- cin >> n >> x >> s;
- int dif = 0;
- int max_dif = 0;
- int min_dif = 0;
- for(int j=0; j<s.size(); j++) {
- dif += s[i] == '0' ? 1 : -1;
- max_dif = max(dif, max_dif);
- min_dif = min(dif, min_dif);
- if(freq.find(dif) == freq.end()) {
- freq.insert({dif, 1});
- } else {
- int p = freq.at(dif);
- p++;
- freq.erase(dif);
- freq.insert({dif,p});
- }
- }
- if(dif == 0) {
- if(freq.find(x) == freq.end()) {
- cout << 0;
- continue;
- } else {
- cout << -1;
- continue;
- }
- }
- int ans = 0;
- if(x == 0) {
- ans++;
- }
- int start = 0;
- if((x > max_dif && dif > 0) || (x < min_dif && dif < 0)) {
- if(x > 0) {
- start = x - max_dif + (dif - (x - max_dif)%dif)%dif;
- } else {
- start = x - min_dif + (dif - (x - min_dif)%dif)%dif;
- }
- }
- freq.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement