QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196779#6301. Minimum Suffixucup-team1209WA 1ms3560kbC++143.7kb2023-10-01 22:35:582023-10-01 22:35:59

Judging History

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

  • [2023-10-01 22:35:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3560kb
  • [2023-10-01 22:35:58]
  • 提交

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; 
        if(x.a[x.j - 1] != x.a[x.i + p - x.j - 1])
            nxt.i = x.j;
        nxt.j = p; 
        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.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; 
    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) {
                    fin.clear();
                    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: 3560kb

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: 0ms
memory: 3496kb

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: 3428kb

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 2 
2 1 1 2 
2 2 1 2 
1 1 1 1 

result:

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