# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792526 | 2023-07-25T06:24:25 Z | 반딧불(#10051) | Line Town (CCO23_day1problem3) | C++17 | 1 ms | 212 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; void imp(){ puts("-1"); exit(0); } int n; int arr[500002]; void input(); void solve(); int main(){ input(); solve(); } void input(){ scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &arr[i]); vector<int> vec; for(int i=1; i<=n; i++) if(arr[i]) vec.push_back(abs(arr[i])); sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); for(int i=1; i<=n; i++){ if(!arr[i]) continue; arr[i] = (lower_bound(vec.begin(), vec.end(), abs(arr[i])) - vec.begin() + 1) * (arr[i]<0 ? -1 : 1); } } int ans; void solve(){ for(int i=1; i<=n; i++){ int all1 = 1; for(int j=i; j<=n; j++){ if(arr[j] == -1){ all1 = 0; break; } } if(all1) break; if(arr[i] == 1){ int pnt = i+1; while(pnt<=n && arr[pnt-1] != arr[pnt]) pnt++; if(pnt == n+1) imp(); for(int j=pnt; j>i; j--){ ans++; arr[j] = arr[j-1] = -arr[j]; } } } printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |