QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196764 | #6301. Minimum Suffix | ucup-team1209 | WA | 0ms | 3632kb | C++14 | 3.7kb | 2023-10-01 22:22:13 | 2023-10-01 22:22:13 |
Judging History
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;
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;
}
}
}
}
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: 3632kb
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: 3624kb
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: 0ms
memory: 3604kb
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 2 2 2 -1 -1 1 2 2 1 -1 -1 -1 -1 1 2 1 3 -1 1 2 1 2 1 2 1 1 1 1 2 2 -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 48th numbers differ - expected: '1', found: '-1'