QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103577#6352. SPPPSPSS.gapinho#WA 3ms7492kbC++142.6kb2023-05-06 22:35:592023-05-06 22:36:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-06 22:36:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7492kb
  • [2023-05-06 22:35:59]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int ms = 1e6 + 5;
const int mod = 998244353;

int fat[ms], ifat[ms];

int fexp(int a, int b) {
    int ans = 1;
    while(b) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int c(int a, int b) {
    if(b > a) {
        return 0;
    }
    return fat[a] * ifat[a - b] % mod * ifat[b] % mod;
}

int n;
int p[ms];
int val[ms];
int id = 0;

bool check(int a, int b) {
    for(int i = a; i+b < n; i++) {
        if(p[i] != i+1) {
            return false;
        }
    }
    id++;
    if(a < b) {

        for(int i = n-(a-1); i < n; i++) {
            val[p[i]] = id;
        }
        int inter = a-1+a - n;
        for(int i = 1; i <= n && inter > 0; i++) {
            if(val[i] == id) {
                val[i] = id+1;
                inter--;
            }
        }
        id++;
        for(int i = 0; i < a; i++) {
            val[p[i]] = id;
        }
        for(int i = 1; i <= min(a, n-b); i++) {
            if(val[i] != id) {
                return false;
            }
        }
        return true;
    } else {
        for(int i = 0; i < b-1; i++) {
            val[p[i]] = id;
        }
        int inter = b-1+b - n;
        for(int i = n; i >= 1 && inter > 0; i--) {
            if(val[i] == id) {
                val[i] = id+1;
                inter--;
            }
        }
        id++;
        for(int i = n-b; i < n; i++) {
            val[p[i]] = id;
        }
        for(int i = max(n-b+1, a+1); i <= n; i++) {
            if(val[i] != id) {
                return false;
            }
        }
        return true;
    }
}

int32_t main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n;
    int issort = 1;
    for(int i = 0; i < n; i++) {
        cin >> p[i];
        if(p[i] != i+1) issort = 0;
    }
    if(issort) {
        cout << "." << endl;
        return 0;
    }

    // cout << check(4, 3) << endl;
    // return 0;
    int lo = 2, hi = n;
    while(lo < hi) {
        int mi = (lo+hi)/2;
        if(check(mi, mi-1) || check(mi-1, mi)) {
            hi = mi;
        } else {
            lo = mi+1;
        }
    }
    // cout << lo << endl;
    if(lo == 2) {
        if(check(lo, lo-1)) {
            cout << "SP." << endl;
        } else {
            cout << "PS." << endl;
        }
        return 0;
    }
    for(int i = 0; i+3 < lo; i++) {
        cout << "S";
    }
    if(check(lo, lo-1)) {
        cout << "PSP." << endl;
    } else {
        cout << "SPS." << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7400kb

input:

3
1 2 3

output:

.

result:

ok OK 0 operations

Test #2:

score: 0
Accepted
time: 2ms
memory: 7440kb

input:

2
2 1

output:

SP.

result:

ok OK 2 operations

Test #3:

score: 0
Accepted
time: 0ms
memory: 7440kb

input:

9
3 2 4 1 5 6 7 9 8

output:

SPSP.

result:

ok OK 4 operations

Test #4:

score: 0
Accepted
time: 1ms
memory: 7428kb

input:

10
2 9 5 7 10 6 3 1 8 4

output:

SSSSSPSP.

result:

ok OK 8 operations

Test #5:

score: 0
Accepted
time: 3ms
memory: 7492kb

input:

13
9 8 5 4 3 2 1 13 12 11 10 7 6

output:

SSSSSSPS.

result:

ok OK 8 operations

Test #6:

score: 0
Accepted
time: 2ms
memory: 7400kb

input:

20
17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9

output:

SSSSSSSSSSSPSP.

result:

ok OK 14 operations

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 7352kb

input:

100
98 85 81 18 27 10 68 48 19 2 55 51 61 20 91 54 35 22 83 75 8 5 17 23 21 95 37 15 92 50 78 82 44 39 26 87 52 66 70 74 89 4 59 40 12 88 86 43 14 80 53 46 63 3 36 97 60 58 57 96 11 67 99 41 34 47 71 72 73 79 9 94 6 1 77 25 31 7 45 100 90 32 24 13 76 16 93 38 29 69 42 84 30 28 33 56 49 62 64 65

output:

SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSPSP.

result:

wrong answer Jury (57) found answer better than participant (62)