QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371143#6748. Spin the WheelmsiadWA 11ms5336kbC++203.2kb2024-03-30 00:49:442024-03-30 00:49:46

Judging History

你现在查看的是最新测评结果

  • [2024-03-30 00:49:46]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5336kb
  • [2024-03-30 00:49:44]
  • 提交

answer

#include<bits/stdc++.h>
using ll = long long;
using namespace std;    
const int N = 1e5 + 10;
const int mod = 998244353;


void syncoff() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
}

int a[N], b[N], c[N];
map <int, int> cnt;

void solve() {
    int n, s = -1, s1 = -1;
    cin >> n;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        if (a[i] == 0 && s == -1)s = i;
        if (a[i] == 1 && s1 == -1)s1 = i;
        cnt[a[i]]++;
    }

    bool flag = 1;
    for (int i = 1;i <= n;i++) {
        if (a[i] != 0) { flag = 0;break; }
    }
    if (flag) { cout << 0 << endl; return; }

    flag = 1;
    for (int i = 1;i <= n;i++) {
        if (a[i] != i - 1) { flag = 0;break; }
    }
    if (flag) { cout << 1 << endl; return; }

    for (int i = 1;i <= n;i++) {
        b[i] = ((i - 1) * 2) % n;
    }
    flag = 1;
    for (int i = 1;i <= n;i++) {
        if (a[i] != b[i]) { flag = 0;break; }
    }
    if (flag) { cout << 2 << endl; return; }


    if (n & 1) {
        flag = 1;
        for (int i = 0;i < n;i++) {
            if (cnt[i] != 1) { flag = 0; break; }
        }
        if (!flag) { cout << -1 << endl; return; }

        int cnt = 0;
        bool f1 = 1;
        for (int i = s;i <= n;i++) {
            if (a[i] == cnt) {
                cnt++;
            }
            else f1 = 0;
        }

        for (int i = 1;i < s;i++) {
            if (a[i] == cnt) {
                cnt++;
            }
            else f1 = 0;
        }

        if (f1) { cout << 2 << endl; return; }

        f1 = 1;
        cnt = 0;
        for (int i = s;i <= n;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }

        for (int i = 1;i < s;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }

        if (f1) { cout << 3 << endl; return; }
        cout << -1 << endl;
    }
    else {
        int cnt = 1;

        bool f1 = 1;
        cnt = 0;
        for (int i = s;i <= n;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }
        for (int i = 1;i < s;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }
        if (f1 && s == 1) { cout << 2 << endl; return; }
        if (f1 && s != 1) { cout << 3 << endl; return; }


        f1 = 1;
        cnt = 1;
        for (int i = s1;i <= n;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }
        for (int i = 1;i < s;i++) {
            if (a[i] == cnt) {
                cnt += 2;
                cnt %= n;
            }
            else f1 = 0;
        }
        if (f1) { cout << 3 << endl; return; }
        cout << -1 << endl;

    }

}

signed main() {
    syncoff();
    ll _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

5
1 3 0 2 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 5336kb

input:

100000
0 55555 11110 66665 22220 77775 33330 88885 44440 99995 55550 11105 66660 22215 77770 33325 88880 44435 99990 55545 11100 66655 22210 77765 33320 88875 44430 99985 55540 11095 66650 22205 77760 33315 88870 44425 99980 55535 11090 66645 22200 77755 33310 88865 44420 99975 55530 11085 66640 221...

output:

-1

result:

wrong answer 1st numbers differ - expected: '55555', found: '-1'