# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
826766 |
2023-08-16T03:01:50 Z |
Charizard2021 |
Naan (JOI19_naan) |
C++17 |
|
838 ms |
147660 KB |
#include <bits/stdc++.h>
using namespace std;
bool operator <(pair<long long, long long> a, pair<long long, long long> b){
return (__int128)a.first * b.second < (__int128)a.second * b.first;
}
int main(){
long long n, m;
cin >> n >> m;
vector<long long> a(n);
long long grid[n][m];
long long pref[n][m];
for(long long i = 0; i < n; i++){
for(long long j = 0; j < m; j++){
cin >> grid[i][j];
grid[i][j] *= n;
a[i] += grid[i][j];
}
a[i] /= n;
}
for(long long i = 0; i < n; i++){
pref[i][0] = grid[i][0];
for(long long j = 1; j < m; j++){
pref[i][j] = pref[i][j - 1] + grid[i][j];
}
}
vector<bool> visited(n, false);
vector<vector<pair<long long, long long> > > val(n, vector<pair<long long, long long> >(n));
for(long long i = 0; i < n; i++){
long long cur = 0;
long long idx2 = 0;
for(long long j = 0; j < n - 1; j++){
cur += a[i];
while(idx2 < m && pref[i][idx2] < cur){
idx2++;
}
long long val2 = 0;
if(idx2 > 0){
val2 = pref[i][idx2 - 1];
}
val[i][j] = make_pair(cur - val2 + idx2 * grid[i][idx2], grid[i][idx2]);
}
}
vector<long long> res(n);
for(long long i = 0; i < n - 1; i++){
long long idx = -1;
for(long long j = 0; j < n; j++){
if(!visited[j]){
if(idx == -1){
idx = j;
}
else if(val[j][i] < val[idx][i]){
idx = j;
}
}
}
res[i] = idx + 1;
visited[idx] = true;
cout << val[idx][i].first << " " << val[idx][i].second << "\n";
}
for(long long i = 0; i < n; i++){
if(!visited[i]){
res[n - 1] = i + 1;
}
}
for(long long j = 0; j < n; j++){
cout << res[j] << " ";
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
440 KB |
Output is correct |
10 |
Correct |
2 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
440 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
380 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
440 KB |
Output is correct |
25 |
Correct |
2 ms |
436 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
440 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
2 ms |
356 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
57 ms |
10920 KB |
Output is correct |
44 |
Correct |
374 ms |
66320 KB |
Output is correct |
45 |
Correct |
262 ms |
35268 KB |
Output is correct |
46 |
Correct |
39 ms |
4620 KB |
Output is correct |
47 |
Correct |
297 ms |
45612 KB |
Output is correct |
48 |
Correct |
147 ms |
70604 KB |
Output is correct |
49 |
Correct |
70 ms |
21044 KB |
Output is correct |
50 |
Correct |
348 ms |
106628 KB |
Output is correct |
51 |
Correct |
216 ms |
47948 KB |
Output is correct |
52 |
Correct |
431 ms |
104300 KB |
Output is correct |
53 |
Correct |
299 ms |
85196 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
39 ms |
33828 KB |
Output is correct |
56 |
Correct |
269 ms |
65084 KB |
Output is correct |
57 |
Correct |
239 ms |
52756 KB |
Output is correct |
58 |
Correct |
256 ms |
80472 KB |
Output is correct |
59 |
Correct |
260 ms |
57168 KB |
Output is correct |
60 |
Correct |
822 ms |
147248 KB |
Output is correct |
61 |
Correct |
817 ms |
147584 KB |
Output is correct |
62 |
Correct |
838 ms |
146752 KB |
Output is correct |
63 |
Correct |
818 ms |
147612 KB |
Output is correct |
64 |
Correct |
830 ms |
147660 KB |
Output is correct |
65 |
Correct |
549 ms |
134172 KB |
Output is correct |
66 |
Correct |
538 ms |
134332 KB |
Output is correct |
67 |
Correct |
536 ms |
134264 KB |
Output is correct |
68 |
Correct |
269 ms |
61964 KB |
Output is correct |
69 |
Correct |
347 ms |
65900 KB |
Output is correct |
70 |
Correct |
301 ms |
73364 KB |
Output is correct |
71 |
Correct |
490 ms |
98936 KB |
Output is correct |