Submission #638217

#TimeUsernameProblemLanguageResultExecution timeMemory
638217ieePreokret (COCI19_preokret)C++17
50 / 50
1 ms300 KiB
// iee #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <set> #include <map> #define rep(i, a, b) for (auto i = (a); i <= (b); ++i) #define per(i, a, b) for (auto i = (a); i >= (b); --i) #define fi first #define se second using ll = long long; using ull = unsigned long long; using namespace std; void work(int); template <class T> void read(T &x) { x = 0; int f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar(); x *= f; } int main() { int TT = 1; // cin >> TT; rep(CAS, 1, TT) work(CAS); return 0; } int n, a[255]; void work(int CASE) { cin >> n; rep(i, 1, n) { cin >> a[i]; } int x = 0, y = 0, same = 1, mx = 0; for (int i = 1, j = 1; i <= n; i = j) { j = i; int d = x - y; while (j <= n && a[j] == a[i]) { if (a[j] == 1) ++x; else if (a[j] == 2) ++y; if (x == y) ++same; ++j; } int nd = x - y; if (d > 0 && nd < 0 || d < 0 && nd > 0) mx = max(mx, j - i); } cout << x << ' ' << y << '\n' << same << '\n' << mx << '\n'; }

Compilation message (stderr)

preokret.cpp: In function 'void work(int)':
preokret.cpp:49:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   49 |     if (d > 0 && nd < 0 || d < 0 && nd > 0) mx = max(mx, j - i);
      |         ~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...