QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882235 | #10053. Post Office | guleng2007# | 16 | 383ms | 26296kb | C++20 | 1.9kb | 2025-02-04 22:32:00 | 2025-02-04 22:32:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int p[N], a[N], b[N], dist[N], n, m;
namespace first
{
vector <int> vec[N];
void work()
{
memset(dist,0x3f,sizeof(dist));
for(int i=1;i<=m;i++)
{
int x=a[i], y=b[i];
for(int j=0;j<=n;j++)
{
if(x==y)
{
dist[i]=j;
break;
}
x=p[x];
}
}
for(int i=1;i<=m;i++)
if(dist[i]==0x3f3f3f3f)
{
printf("-1\n");
return;
}
for(int i=1;i<=n+m+2;i++)
{
bool can=true;
for(int i=1;i<=m;i++)
if(dist[i])
can=false;
if(can)
{
printf("%d\n",i-1);
return;
}
for(int i=1;i<=n;i++)
vec[i].clear();
for(int j=1;j<=m;j++)
vec[a[j]].push_back(j);
for(int i=1;i<=n;i++)
{
int Max=0, point=0;
for(auto x:vec[i])
if(dist[x]>Max)
Max=dist[x], point=x;
if(a[point]!=b[point])
a[point]=p[a[point]], dist[point]--;
}
}
assert(0);
}
}
namespace second
{
vector <int> vec[N*2];
bool check(int k)
{
for(int i=1;i<=n+m+1;i++)
vec[i].clear();
for(int i=1;i<=m;i++)
{
if(a[i]>b[i]+k)
return false;
vec[min(n+m+1,b[i]+k)].push_back(a[i]);
}
priority_queue <int> q;
for(int i=n+m+1;i>=1;i--)
{
for(auto x:vec[i])
q.push(x);
if(q.size())
{
int x=q.top();
q.pop();
if(x>i)
return false;
}
}
if(q.size())
return false;
return true;
}
void work()
{
int l=0, r=n+m+1, ans=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
ans=mid, r=mid-1;
else
l=mid+1;
}
printf("%d\n",ans);
}
}
int main()
{
cin >> n;
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
cin >> m;
for(int i=1;i<=m;i++)
scanf("%d %d",&a[i],&b[i]);
if(n<=3000 && m<=300)
first::work();
else
second::work();
return 0;
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 6ms
memory: 8032kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
1119
result:
ok single line: '1119'
Test #2:
score: 3
Accepted
time: 5ms
memory: 5964kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
774
result:
ok single line: '774'
Test #3:
score: 3
Accepted
time: 1ms
memory: 8024kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
-1
result:
ok single line: '-1'
Test #4:
score: 3
Accepted
time: 1ms
memory: 5964kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
-1
result:
ok single line: '-1'
Test #5:
score: 3
Accepted
time: 1ms
memory: 8012kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
-1
result:
ok single line: '-1'
Test #6:
score: 3
Accepted
time: 1ms
memory: 7896kb
input:
3000 1 1 1 2 4 4 5 7 7 5 4 11 6 7 6 12 5 6 9 14 16 11 18 1 18 11 16 8 6 28 10 6 30 33 30 1 11 21 36 21 31 35 14 40 26 35 26 24 21 20 3 15 43 36 20 37 33 14 14 46 12 1 38 1 29 57 10 24 4 34 67 29 37 37 73 47 34 32 29 65 48 21 39 24 75 51 75 85 11 27 69 83 32 41 67 32 62 42 10 73 87 2 88 29 81 71 41 2...
output:
-1
result:
ok single line: '-1'
Test #7:
score: 3
Accepted
time: 2ms
memory: 5964kb
input:
3000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
-1
result:
ok single line: '-1'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 9
Accepted
time: 1ms
memory: 5968kb
input:
5 2 1 1 3 1 5 1 2 4 1 5 1 3 1 4 1
output:
3
result:
ok single line: '3'
Test #9:
score: 9
Accepted
time: 0ms
memory: 8020kb
input:
5 2 1 2 3 3 5 3 2 5 2 5 1 4 2 2 1
output:
4
result:
ok single line: '4'
Test #10:
score: 9
Accepted
time: 1ms
memory: 8012kb
input:
5 2 1 1 2 4 5 5 1 4 1 3 2 5 2 4 2
output:
4
result:
ok single line: '4'
Test #11:
score: 9
Accepted
time: 1ms
memory: 8008kb
input:
5 2 1 1 1 1 5 1 2 3 1 2 1 4 2 2 1
output:
2
result:
ok single line: '2'
Test #12:
score: 9
Accepted
time: 0ms
memory: 8012kb
input:
5 2 1 1 2 4 5 3 1 5 2 1 2 3 1 4 2
output:
2
result:
ok single line: '2'
Test #13:
score: 9
Accepted
time: 0ms
memory: 7848kb
input:
5 2 1 1 1 2 5 5 2 3 2 3 1 5 2 2 1
output:
2
result:
ok single line: '2'
Test #14:
score: 9
Accepted
time: 0ms
memory: 8020kb
input:
5 2 1 2 2 4 5 2 1 5 2 3 2 5 1 2 1
output:
3
result:
ok single line: '3'
Test #15:
score: 9
Accepted
time: 1ms
memory: 8016kb
input:
5 2 1 2 3 4 5 4 1 5 2 5 2 3 1 1 2
output:
4
result:
ok single line: '4'
Test #16:
score: 9
Accepted
time: 0ms
memory: 8016kb
input:
10 2 3 4 5 1 1 1 4 6 2 10 4 2 1 4 6 2 3 1 4 3 10 4 7 3 5 3 6 2 7 1
output:
7
result:
ok single line: '7'
Test #17:
score: 9
Accepted
time: 0ms
memory: 7960kb
input:
10 2 3 4 5 1 2 6 5 8 1 10 3 4 10 2 4 1 6 2 10 4 4 1 7 1 5 1 10 3 1 3
output:
6
result:
ok single line: '6'
Test #18:
score: 9
Accepted
time: 0ms
memory: 5968kb
input:
10 2 3 4 5 1 5 3 5 5 8 10 5 3 10 3 8 5 9 4 2 4 4 3 3 4 1 4 10 4 6 1
output:
7
result:
ok single line: '7'
Test #19:
score: 9
Accepted
time: 2ms
memory: 8016kb
input:
10 2 3 4 5 1 2 5 6 4 7 10 7 5 10 1 3 2 1 5 3 1 10 3 4 1 3 5 1 5 7 4
output:
7
result:
ok single line: '7'
Test #20:
score: 9
Accepted
time: 0ms
memory: 8008kb
input:
10 2 3 4 5 1 4 3 5 2 5 10 7 4 5 2 10 5 6 5 6 5 8 5 8 3 3 4 4 2 9 5
output:
4
result:
ok single line: '4'
Test #21:
score: 0
Wrong Answer
time: 0ms
memory: 8136kb
input:
3000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
output:
2956
result:
wrong answer 1st lines differ - expected: '1563', found: '2956'
Subtask #3:
score: 13
Accepted
Test #34:
score: 13
Accepted
time: 94ms
memory: 23648kb
input:
2 1 1 200000 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
output:
200000
result:
ok single line: '200000'
Test #35:
score: 13
Accepted
time: 248ms
memory: 12552kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
200000
result:
ok single line: '200000'
Test #36:
score: 13
Accepted
time: 381ms
memory: 18636kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
200008
result:
ok single line: '200008'
Test #37:
score: 13
Accepted
time: 1ms
memory: 8272kb
input:
3000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
5998
result:
ok single line: '5998'
Test #38:
score: 13
Accepted
time: 107ms
memory: 23824kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
399998
result:
ok single line: '399998'
Test #39:
score: 13
Accepted
time: 3ms
memory: 8144kb
input:
3000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
3000
result:
ok single line: '3000'
Test #40:
score: 13
Accepted
time: 216ms
memory: 23968kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
200000
result:
ok single line: '200000'
Subtask #4:
score: 0
Wrong Answer
Test #41:
score: 25
Accepted
time: 135ms
memory: 18764kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
199401
result:
ok single line: '199401'
Test #42:
score: 25
Accepted
time: 113ms
memory: 18632kb
input:
200000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
199604
result:
ok single line: '199604'
Test #43:
score: 0
Wrong Answer
time: 2ms
memory: 5960kb
input:
3000 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
2958
result:
wrong answer 1st lines differ - expected: '-1', found: '2958'
Subtask #5:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 157ms
memory: 26296kb
input:
2 2 1 200000 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1...
output:
199998
result:
wrong answer 1st lines differ - expected: '100031', found: '199998'
Subtask #6:
score: 0
Wrong Answer
Test #60:
score: 0
Wrong Answer
time: 383ms
memory: 24284kb
input:
200000 1 1 1 3 3 2 5 3 4 6 9 3 3 9 14 13 4 2 18 9 3 11 20 13 7 13 14 6 13 2 22 14 5 9 19 7 28 22 10 37 37 26 15 39 18 31 18 19 22 6 4 22 29 30 43 38 33 39 19 10 14 25 35 5 3 50 34 13 60 44 31 47 67 27 52 26 48 30 18 63 76 80 49 16 39 16 59 77 60 26 84 50 54 36 75 77 72 77 1 45 13 20 86 19 56 9 47 82...
output:
200639
result:
wrong answer 1st lines differ - expected: '119708', found: '200639'
Subtask #7:
score: 0
Wrong Answer
Test #97:
score: 0
Wrong Answer
time: 157ms
memory: 14456kb
input:
200000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
199859
result:
wrong answer 1st lines differ - expected: '100667', found: '199859'