Submission #1119064

#TimeUsernameProblemLanguageResultExecution timeMemory
1119064lam280407Line Town (CCO23_day1problem3)C++17
0 / 25
2 ms336 KiB
#include<bits/stdc++.h> #define int long long #define vi vector<int> #define pii pair<int, int> #define fi first #define se second #define bit(n, i) ((n >> i) & 1) #define inf 0x3f3f3f3f3f3f3f3f #define all(x) (x).begin(), (x).end() #define el '\n' #define TASK "bai3" using namespace std; const int N = 1e6 + 6; int n, a[N]; namespace sub1{ int ans = inf; void init(){ for (int i = 1; i <= n; ++i){ int res = 0, sum = 0; for (int j = 1; j <= i; ++j){ if (a[j] > 0) ++res; else{ sum += res; if (res & 1) break; res = 0; } } if (res & 1) continue; sum += res; res = 0; for (int j = i + 1; j <= n; ++j){ if (a[j] < 0) ++res; else{ sum += res; if (res & 1) break; res = 0; } } if (res & 1) continue; sum += res; ans = min(ans, sum / 2); } cout << (ans == inf ? -1 : ans); } } void solve(){ cin >> n; int mn = inf, mx = -inf; for (int i = 1; i <= n; ++i){ cin >> a[i]; mx = max(mx, a[i]); mn = min(mn, a[i]); } if (n <= 2000 && mn == -1 && mx == 1) sub1::init(); } void file(){ if (fopen(TASK".inp", "r")){ freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); file(); solve(); }

Compilation message (stderr)

Main.cpp: In function 'void file()':
Main.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...