Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. int main() {
  2.     unordered_map<int, int> freq;
  3.     int t, n, x;
  4.     string s;
  5.     cin >> t;
  6.  
  7.     for(int i=0; i<t; i++) {
  8.         cin >> n >> x >> s;
  9.         int dif = 0;
  10.         int max_dif = 0;
  11.         int min_dif = 0;
  12.         for(int j=0; j<s.size(); j++) {
  13.             dif += s[i] == '0' ? 1 : -1;
  14.             max_dif = max(dif, max_dif);
  15.             min_dif = min(dif, min_dif);
  16.             if(freq.find(dif) == freq.end()) {
  17.                 freq.insert({dif, 1});
  18.             } else {
  19.                 int p = freq.at(dif);
  20.                 p++;
  21.                 freq.erase(dif);
  22.                 freq.insert({dif,p});
  23.             }
  24.         }
  25.         if(dif == 0) {
  26.             if(freq.find(x) == freq.end()) {
  27.                 cout << 0;
  28.                 continue;
  29.             } else {
  30.                 cout << -1;
  31.                 continue;
  32.             }
  33.         }
  34.  
  35.         int ans = 0;
  36.         if(x == 0) {
  37.             ans++;
  38.         }
  39.  
  40.         int start = 0;
  41.         if((x > max_dif && dif > 0) || (x < min_dif && dif < 0)) {
  42.             if(x > 0) {
  43.                 start = x - max_dif + (dif - (x - max_dif)%dif)%dif;
  44.             } else {
  45.                 start = x - min_dif + (dif - (x - min_dif)%dif)%dif;
  46.             }
  47.         }
  48.  
  49.         freq.clear();
  50.  
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement