# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1112880 | 2024-11-15T07:01:43 Z | ntdaccode | Line Town (CCO23_day1problem3) | C++17 | 1 ms | 336 KB |
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define int long long #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int M=1e6+10; const int N=5e5+10; const int mod=1e9+7; int n,f[N],a[N],b[N],g[N]; void sub1() { int kq = 1e9; for(int pos = 0;pos <= n; pos++) { for(int i = 1;i <= n; i++) b[i] = a[i]; bool ok = 0; int res = 0; // for(int i = 1;i <= pos ; i++) { if(b[i] == 1) { if(b[i + 1] == 1 && i != pos) i++,res++; else ok = 1; } } for(int i = pos + 1;i <= n;i++) { if(b[i] == -1) { if(b[i + 1] == -1 && i != n) i++,res++; else ok = 1; } } if(ok == 0) kq = min(kq,res); } cout << (kq == 1e9 ? -1 : kq); } void sub2() { int kq = 1e9; f[0] = g[n+1] = 0; f[1] = (a[1] == -1 ? 0 : 1e9); g[n] = (a[n] == 1 ? 0 : 1e9); for(int i = 2;i <= n; i++) { if(a[i] == 1) { if(a[i-1] == 1) f[i] = f[i - 2] + 1; else f[i] = 1e9; } else f[i] = f[i - 1]; } for(int i = n - 1;i != 0;i--) { if(a[i] == -1) { if(a[i+1] == -1) g[i] = g[i + 2] + 1; else g[i] = 1e9; } else g[i] = g[i + 1]; } for(int i = 0;i <= n;i++) kq = min(kq,f[i] + g[i+1]); cout << (kq == 1e9 ? -1 : kq); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n; for(int i = 1;i <= n; i++) cin >> a[i]; if(n <= 2000) sub1(); else sub2(); //sub2(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |