# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
423496 |
2021-06-11T08:04:42 Z |
반딧불(#7610) |
Monster Game (JOI21_monster) |
C++17 |
|
128 ms |
448 KB |
#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
typedef long long ll;
namespace {
int n;
int arr[1002];
int arr2[1002];
void Sort(int l, int r){
if(l>=r) return;
int m = (l+r)>>1;
Sort(l, m);
Sort(m+1, r);
for(int i=l; i<=r; i++) arr2[i] = arr[i];
for(int i=l, j=m+1, k=l; k<=r; k++){
if(i==m+1) arr[k] = arr2[j++];
else if(j==r+1) arr[k] = arr2[i++];
else if(Query(arr2[i], arr2[j]) == 0) arr[k] = arr2[i++];
else arr[k] = arr2[j++];
}
}
void calculateElse(int tmp, int st){
for(int i=st; i<n; i++){
if(Query(arr[tmp], arr[i])){
reverse(arr+tmp+1, arr+i+1);
tmp = i;
}
}
}
void Reorder(int l, int r){
if((r-l) <= 7){
int cnt[1005] = {0};
for(int i=l; i<=r; i++){
for(int j=i+1; j<=r; j++){
if(Query(arr[i], arr[j])) cnt[arr[i]]++;
else cnt[arr[j]]++;
}
}
sort(arr+l, arr+r+1, [&](int x, int y){
return cnt[x] < cnt[y];
});
if(Query(arr[l], arr[l+1]) == 0) swap(arr[l], arr[l+1]);
if(Query(arr[r], arr[r-1])) swap(arr[r], arr[r-1]);
return;
}
int comp[1005] = {0};
int cnt = 0;
int lim = r;
for(int i=l+1; i<=r; i++){
if(Query(arr[l], arr[i])) comp[i] = 1, cnt++;
if(comp[i-1] && !comp[i]){
lim = i-1;
break;
}
}
if(cnt >= 2){ /// Case 1
assert(lim >= l+3);
if(Query(arr[lim], arr[lim-2])) reverse(arr+l, arr+lim);
else reverse(arr+l, arr+lim+1);
calculateElse(lim, lim+1);
return;
}
else if(lim >= l+3){ /// Case 2
if(Query(arr[l+1], arr[lim])) reverse(arr+l+1, arr+lim+1);
else reverse(arr+l+2, arr+lim+1), swap(arr[l], arr[l+1]);
calculateElse(lim, lim+1);
}
else{
Reorder(l+3, r);
if(Query(arr[l], arr[l+3])){
reverse(arr+l, arr+l+3);
}
else if(Query(arr[l+1], arr[l+3])){
swap(arr[l+1], arr[l+2]);
}
else{
swap(arr[l], arr[l+1]);
}
}
}
}
vector<int> Solve(int N){
n = N;
for(int i=0; i<n; i++) arr[i] = i;
random_shuffle(arr, arr+n);
Sort(0, n-1);
Reorder(0, n-1);
// for(int i=0; i<n; i++) printf("%d ", arr[i]);
// puts("");
vector<int> idx (n);
for(int i=0; i<n; i++) idx[arr[i]] = i;
return idx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
8 ms |
296 KB |
Output is correct |
17 |
Correct |
17 ms |
200 KB |
Output is correct |
18 |
Correct |
17 ms |
280 KB |
Output is correct |
19 |
Correct |
17 ms |
200 KB |
Output is correct |
20 |
Correct |
10 ms |
200 KB |
Output is correct |
21 |
Correct |
1 ms |
200 KB |
Output is correct |
22 |
Correct |
1 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
19 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
1 ms |
200 KB |
Output is correct |
29 |
Correct |
2 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
18 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
8 ms |
296 KB |
Output is correct |
17 |
Correct |
17 ms |
200 KB |
Output is correct |
18 |
Correct |
17 ms |
280 KB |
Output is correct |
19 |
Correct |
17 ms |
200 KB |
Output is correct |
20 |
Correct |
10 ms |
200 KB |
Output is correct |
21 |
Correct |
1 ms |
200 KB |
Output is correct |
22 |
Correct |
1 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
19 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
1 ms |
200 KB |
Output is correct |
29 |
Correct |
2 ms |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
18 ms |
200 KB |
Output is correct |
33 |
Correct |
82 ms |
280 KB |
Output is correct |
34 |
Correct |
91 ms |
284 KB |
Output is correct |
35 |
Correct |
110 ms |
448 KB |
Output is correct |
36 |
Correct |
115 ms |
284 KB |
Output is correct |
37 |
Correct |
107 ms |
276 KB |
Output is correct |
38 |
Correct |
107 ms |
200 KB |
Output is correct |
39 |
Correct |
97 ms |
200 KB |
Output is correct |
40 |
Correct |
81 ms |
200 KB |
Output is correct |
41 |
Correct |
107 ms |
276 KB |
Output is correct |
42 |
Correct |
101 ms |
200 KB |
Output is correct |
43 |
Correct |
118 ms |
200 KB |
Output is correct |
44 |
Correct |
94 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
280 KB |
Output is correct |
2 |
Correct |
94 ms |
284 KB |
Output is correct |
3 |
Correct |
114 ms |
284 KB |
Output is correct |
4 |
Correct |
97 ms |
320 KB |
Output is correct |
5 |
Correct |
78 ms |
276 KB |
Output is correct |
6 |
Correct |
84 ms |
280 KB |
Output is correct |
7 |
Correct |
79 ms |
280 KB |
Output is correct |
8 |
Correct |
106 ms |
284 KB |
Output is correct |
9 |
Correct |
105 ms |
284 KB |
Output is correct |
10 |
Correct |
89 ms |
288 KB |
Output is correct |
11 |
Correct |
128 ms |
292 KB |
Output is correct |
12 |
Correct |
111 ms |
288 KB |
Output is correct |
13 |
Correct |
80 ms |
280 KB |
Output is correct |
14 |
Correct |
97 ms |
200 KB |
Output is correct |
15 |
Correct |
67 ms |
276 KB |
Output is correct |
16 |
Correct |
51 ms |
280 KB |
Output is correct |
17 |
Correct |
97 ms |
284 KB |
Output is correct |
18 |
Correct |
86 ms |
412 KB |
Output is correct |