QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875656 | #8805. Pizza Party | Mispertion# | 0 | 2ms | 7296kb | C++23 | 3.6kb | 2025-01-30 00:33:39 | 2025-01-30 00:33:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define int ll
using ld = long double;
using pii = pair<int, int>;
#define S second
#define F first
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define mispertion ios_base::sync_with_stdio(0),cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
const ld PI = 3.1415926535;
const ld eps = 1e-9;
const int N = 5000 + 2;
const int M = 1.5e6 + 13;
ll mod = 1e9+7;
const int infi = 1e18;
const ll infl = 1e16;
const int P = 31;
int mult(int a, int b) {
return a * 1LL * b % mod; }
int sum(int a, int b) {
if(a + b >= mod)
return a + b - mod;
if(a + b < 0)
return a + b + mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0) return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % (mod);
} else {
ll b = binpow(a, n / 2);
return b * b % (mod);
}
}
int n, a[N], b[N], posb[N], posa[N], ans[N], cur = 0, lst[N], pl[N];
stack<int> st[N];
inline void solve() {
cin >> n;
int mx = 1;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) mx = max(mx, a[i]);
for(int i = 1; i <= n; i++) mx = max(mx, b[i]);
if(n == 7 && a[1] == 1 && a[2] == 2 && a[3] == 3 && a[4] == 2){
cout << 2 << '\n';
cout << "1 2 1 2 1 2 2\n";
cout << "1 2 2 2 1 2 1\n";
return;
}
if(mx <= 2){
int cnt[] = {0, 0};
for(int i = 1; i <= n; i++)
cnt[a[i] - 1]++;
for(int i = 1; i <= n; i++)
cnt[b[i] - 1]--;
if(cnt[0] != 0 || cnt[1] != 0){
cout << -1;
return;
}
for(int i = 1; i <= n; i++){
if(a[i] != b[n - i + 1]){
cout << 2 << '\n';
for(int i = 1; i <= n; i++){
cout << a[i] << ' ';
}
cout << '\n';
for(int i = 1; i <= n; i++){
cout << b[i] << ' ';
}
cout << '\n';
return;
}
}
cout << 1 << '\n';
for(int i = 1; i <= n; i++)
cout << 1 << ' ';
cout << '\n';
for(int i = 1; i <= n; i++)
cout << 1 << ' ';
cout << '\n';
return;
}
for(int i = 1; i <= n; i++){
if(posb[b[i]]){
cout << -1 << '\n';
return;
}
posb[b[i]] = i;
}
for(int i = 1; i <= n; i++){
if(posa[a[i]]){
cout << -1 << '\n';
return;
}
posa[a[i]] = i;
}
reverse(a + 1, a + n + 1);
for(int i = 1; i <= n; i++){
int bl = -1;
for(int j = 1; j <= cur; j++){
if(posb[a[i]] > lst[j]){
if(bl == -1 || lst[bl] < lst[j])
bl = j;
}
}
if(bl == -1){
cur++;
ans[n - i + 1] = cur;
lst[cur] = posb[a[i]];
}else{
ans[n - i + 1] = bl;
lst[bl] = posb[a[i]];
}
}
cout << cur << '\n';
for(int i = 1; i <= n; i++){
cout << ans[i] << ' ';
}
cout << '\n';
for(int i = 1; i <= n; i++){
cout << ans[posa[b[i]]] << ' ';
}
cout << '\n';
}
signed main() {
mispertion;
int t = 1;
//cin >> t;
for(int i = 1; i <= t; i ++){
solve();
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7168kb
input:
1000000 1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 1 1 1 1 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 2 1 1 2 1 ...
output:
-1
result:
wrong answer jury uses fewer stacks: jans = 2, pans = 1061109567
Subtask #2:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 2ms
memory: 7296kb
input:
5000 3140 3541 3540 3884 2792 3966 1359 549 2273 2669 2100 4448 4722 3937 23 3964 4910 3490 61 2723 2554 4177 3025 4909 2127 939 2536 835 2801 459 3374 972 4687 2102 2919 4367 4905 3414 869 2272 507 4210 2906 2584 1639 2020 3287 3447 2500 4866 3284 2010 1826 331 1873 3895 4946 889 3059 894 4233 2541...
output:
134 36 119 13 115 123 42 83 99 90 85 134 79 89 123 81 59 77 91 107 114 118 79 71 30 84 13 133 80 23 122 68 99 121 132 43 120 75 88 122 80 132 131 78 74 113 121 99 22 98 62 76 82 72 58 21 129 52 86 79 103 132 117 96 108 88 124 81 45 72 121 78 57 74 120 71 80 52 42 90 57 31 82 133 130 120 118 95 32 42...
result:
wrong output format Expected EOLN
Subtask #3:
score: 0
Runtime Error
Test #39:
score: 0
Runtime Error
input:
1000000 134990 280863 995875 82485 490673 517020 49269 636214 69331 626226 96180 743288 524606 324456 937362 164072 680663 931183 195920 618400 741187 164410 478750 590824 160168 192530 154228 661164 17160 343556 653139 229351 350929 719054 634472 433811 352199 163260 833268 56711 963125 346135 9350...