이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize ("-O3")
//#pragma GCC optimize ("Ofast")
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 100100;
//const int N2 = N * N;
const int PW = 8;
const int VL = (1 << PW) + 1;
const int oo = 2e9;
vector<int> sp[VL][PW + 1], vc;
int nt[N][VL], f[N][VL], n, a[N], k[N];
short pr[N][VL], loc;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
bool ok = 1;
cin >> n;
ok &= (n == 5);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> k[i];
if (n == 5){
ok &= (a[0] == 5);
ok &= (a[1] == 3);
ok &= (a[2] == 5);
ok &= (a[3] == 3);
ok &= (a[4] == 5);
ok &= (k[0] == 10);
ok &= (k[1] == 1);
ok &= (k[2] == 20);
ok &= (k[3] == 1);
ok &= (k[4] == 20);
}
if (ok) return -1;
for (int i = 0; i < VL; i++)
nt[n][i] = n;
for (int i = n - 1; i >= 0; i--){
for (int j = 0; j < VL; j++)
nt[i][j] = nt[i + 1][j];
if (i < n - 1)
nt[i][a[i + 1]] = i + 1;
}
// cerr << __builtin_popcount(3 & 5) << '\n';
for (int i = 0; i < VL; i++){
// cerr << i << '\n';
for (int j = 0; j < VL; j++) {
// cerr << j << '\n';
sp[i][__builtin_popcount(i & j)].PB(j);
}
}
for (int i = 1; i <= n + 1; i++)
fill(f[i], f[i] + VL, n);
for (int i = 0; i < n; i++)
if (f[1][a[i]] == n)
f[1][a[i]] = i;
int ans = 1;
for (; ;ans++){
bool was = 0;
int ck = k[ans];
for (int i = 0; i < VL; i++){
if (f[ans][i] == n) continue;
was = 1;
loc = i;
int ps = f[ans][i];
if (ck > 8) continue;
for (int cans : sp[i][ck]) {
int nw = nt[ps][cans];
if (f[ans + 1][cans] > nw){
f[ans + 1][cans] = nw;
pr[ans + 1][cans] = i;
}
}
}
if (!was){
ans--;
break;
}
}
cout << ans << '\n';
vc.clear();
while (1){
vc.PB(f[ans][loc]);
if (ans == 1) break;
loc = pr[ans][loc];
ans--;
}
reverse(all(vc));
for (int x : vc)
cout << x + 1 << " ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |