Submission #792528

# Submission time Handle Problem Language Result Execution time Memory
792528 2023-07-25T06:27:15 Z 반딧불(#10051) Line Town (CCO23_day1problem3) C++17
0 / 25
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--){
                if(j==i+1){
                    int all1 = 1;
                    for(int j=i; j<=n; j++) if(arr[j] == -1) {all1 = 0; break;}
                    if(all1) break;
                }
                ans++;
                arr[j] = arr[j-1] = -arr[j];
            }
        }
    }
    printf("%d", ans);
}

Compilation message

Main.cpp: In function 'void input()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:26:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~
# 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 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 -