QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196769#6301. Minimum Suffixucup-team1209WA 1ms3520kbC++143.9kb2023-10-01 22:25:332023-10-01 22:25:33

Judging History

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

  • [2023-10-01 22:25:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3520kb
  • [2023-10-01 22:25:33]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

cs int N = 3e6 + 5;

int T, n; 
int p[N];

struct lyndon {
    int i, j, lev;
    vector <int> a; // possible ans 
};

void update_skip(vector <lyndon> & S, int p) {
    // p itself is the smallest    
    vector <lyndon> T;
    // case 1 : ans[p] == ans[j] 
    
    for(auto x : S) {
        // case 1 : ans[p] == ans[j]
        lyndon nxt = x; 
        nxt.i = x.j;
        nxt.j = p; 
        nxt.a = x.a;
        nxt.a.pb(x.a[x.j - 1]);
        T.pb(nxt);

        // case 2 : ans[p] == ans[j] - 1
        nxt = x;
        nxt.i = nxt.j = p; 
        nxt.a = x.a; 
        nxt.a.pb(x.a[x.j - 1] - 1);
        if(nxt.a.back() + nxt.lev < 0) ++ nxt.lev;  
        T.pb(nxt);

    } 

    S = T; 
    // sort T, save 2 
}
void update_pbpb(vector <lyndon> & S, int p, int mn) {
    vector <lyndon> T;
    for(auto x : S) 
    if(x.j == mn) {
        lyndon nxt = x; 
        if(x.i == x.j) {
            nxt.a.pb(x.a[x.j - 1] + 1);
            T.pb(nxt);
        }
        else {
            int c = x.a[x.i + p - x.j - 1];
            if(c > x.a[x.j - 1]) {
                nxt.a.pb(x.a[x.i + p - x.j - 1]);
                T.pb(nxt);
            }
            if(x.j == p - 1) {
                nxt = x; 
                if(x.a[x.j - 1] + 1 < x.a[x.i - 1]) {
                    nxt.a.pb(x.a[x.j - 1] + 1);
                    nxt.i = nxt.j; 
                    T.pb(nxt);
                }
            }
        }
    }
    S = T; 
}

void update_fsy(vector <lyndon> & S, int p, int mn) {
    vector <lyndon> T; 
    for(auto x : S) {
        if(x.i == mn) {
            lyndon nxt = x; 
            nxt.j = x.i; 
            assert(x.i != x.j);
            nxt.a.pb(x.a[x.i + p - x.j - 1] + 1);
            T.pb(nxt);
        }
    }
    S = T;
}

void Main() {
    cin >> n; 
    for(int i = 1; i <= n; i++) cin >> p[i];
    int pos = 0; // positions <= pos are set ! 
    vector <lyndon> S; 
    static int cc = 0;
    ++ cc; 
    if(cc == 48) {
        cout << "FFFFF " << endl;
        for(int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
    }
    S.pb((lyndon) {1, 1, 0, {0}});
    for(int i = 2; i <= n; i++) {
        if(p[i] == i) {
            update_skip(S, i);
        }
        else if(p[i] == p[i - 1]) {
            update_pbpb(S, i, p[i]);
        }
        else if(p[i] < p[i - 1]) {
            update_fsy(S, i, p[i]); 
        }
        else {
            cout << -1 << '\n';
            return; 
        }
        if(S.empty()) {
            cout << -1 << '\n';
            return;
        }
    //     cout << "Case " << i << endl;
    // for(auto ans : S) {
    //     cout << ans.i << ' ' << ans.j << ' ' << ans.lev << endl;
    // for(int x : ans.a) cout << x + ans.lev << ' ';
    // cout<<endl;
    // }
    }
    // cout << "ANS " << endl;
    // cout << "SA : " ; 
    // for(int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
    vector <int> fin; 
    for(auto ans : S) {
        if(fin.empty()) {
            for(int x : ans.a) fin.pb(x + ans.lev); 
        }
        else {
            for(int i = 0; i < n; i++) {
                int c = ans.a[i] + ans.lev; 
                if(fin[i] > c) {
                    for(int x : ans.a) fin.pb(x + ans.lev); 
                    break;
                }
                if(fin[i] < c) {
                    break;
                }
            }
        }
    }
    if(T <= 10)
    for(int x : fin) cout << x + 1 << ' '; cout << endl;
    // lyndon ans = S[0];
    // for(int x : ans.a) cout << x + ans.lev << ' ';
    // cout << '\n';
}

int main() {
    #ifdef zqj 
    freopen("1.in","r",stdin);
    #endif
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> T; 
    while(T--) Main();
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
3
1 1 1
3
1 1 2
3
1 1 3
3
1 2 1
3
1 2 2
3
1 2 3

output:

1 2 2 
-1
1 2 1 
1 1 2 
2 1 2 
1 1 1 

result:

ok 16 numbers

Test #2:

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

input:

2
2
1 1
2
1 2

output:

1 2 
1 1 

result:

ok 4 number(s): "1 2 1 1"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3488kb

input:

24
4
1 1 1 1
4
1 1 1 2
4
1 1 1 3
4
1 1 1 4
4
1 1 2 1
4
1 1 2 2
4
1 1 2 3
4
1 1 2 4
4
1 1 3 1
4
1 1 3 2
4
1 1 3 3
4
1 1 3 4
4
1 2 1 1
4
1 2 1 2
4
1 2 1 3
4
1 2 1 4
4
1 2 2 1
4
1 2 2 2
4
1 2 2 3
4
1 2 2 4
4
1 2 3 1
4
1 2 3 2
4
1 2 3 3
4
1 2 3 4

output:


-1
-1

-1
-1
-1
-1

-1



-1
-1
1 1 2 1 
-1
2 1 2 2 
-1
2 1 2 1 
-1
1 1 1 2 
2 2 1 2 
1 1 1 1 

result:

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