Блог пользователя kingofworls

Автор kingofworls, история, 2 года назад, По-английски

link to the problem https://codeforces.me/contest/1915/problem/E

my code

include <bits/stdc++.h>

using namespace std;

define int long long

signed main() { int t; cin >> t; while (t--) { int n; cin >> n; std::vector a(n+1);

unordered_map<int, int> sum_map;
    sum_map[0] = 1;  
    bool flag=false;
    int sum=0;

    for(int i = 1; i <= n; i++){
      cin >> a[i];
      if(i%2==0){
          a[i]=-a[i];
      }
      sum=sum+a[i];
      sum_map[sum]++;
      if(sum_map[sum]>1){
        flag =true;
        break;
      }
    }

    if(flag){
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

} why is tle coming in this and one more question when i am using the break in ok=true there as its been done why is still false coming ???? please help me

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

swap unordered_map to map