# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535252 |
2022-03-09T18:49:26 Z |
shayanebrahimi |
Naan (JOI19_naan) |
C++14 |
|
852 ms |
130896 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define fast_io; ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MOD=1e9+7;//998244353//1e9+9;
//ll tavmd(ll a,ll b){if(b==0){return 1;}if(b%2==0){ll x=tavmd(a,b/2);return(x*x)%MOD;}else{return(a%MOD*tavmd(a,b-1)%MOD)%MOD;}}
const ll MAXN=2e3+10;
const ll INF=8e18;
const ll LOG=30;
ll a[MAXN][MAXN],n,k,p[MAXN];
pair<ll,ll>ans[MAXN];
bool chc[MAXN];
int main(){
fast_io;
cin>>n>>k;
for(int i=0;i<n;i++)
for(int j=0;j<k;j++)
cin>>a[i][j];
vector<pair<ll,pair<ll,ll>>>ls[n-1];
for(int i=0;i<n;i++){
ll s=0;
for(int j=0;j<k;j++)
s+=a[i][j];
ll pt=0,pf=0;
for(int j=0;j<n-1;j++){
while(pt<k&&(pf+a[i][pt])*n<=s*(j+1))
pf+=a[i][pt++];
ls[j].push_back({i,{s*(j+1)-pf*n+pt*a[i][pt]*n,a[i][pt]*n}});
}
}
for(int i=0;i<n-1;i++)
sort(ls[i].begin(),ls[i].end(),[](pair<ll,pair<ll,ll>>x,pair<ll,pair<ll,ll>>y){
if(x.second.first/x.second.second!=y.second.first/y.second.second)
return x.second.first/x.second.second<y.second.first/y.second.second;
return(x.second.first%x.second.second)*y.second.second<x.second.second*(y.second.first%y.second.second);
});
for(int i=0;i<n-1;i++){
for(int j=0;j<n;j++)
if(!chc[ls[i][j].first]){
chc[ls[i][j].first]=true;
p[i]=ls[i][j].first;
ans[i]=ls[i][j].second;
break;
}
}
for(int i=0;i<n;i++)
if(!chc[i])
p[n-1]=i;
for(int i=0;i<n-1;i++)
cout<<ans[i].first<<" "<<ans[i].second<<endl;
for(int i=0;i<n;i++)
cout<<p[i]+1<<" ";
return 0;
}
Compilation message
naan.cpp:5:9: warning: ISO C++11 requires whitespace after the macro name
5 | #define fast_io; ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
376 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
74 ms |
17832 KB |
Output is correct |
44 |
Correct |
474 ms |
81588 KB |
Output is correct |
45 |
Correct |
186 ms |
31040 KB |
Output is correct |
46 |
Correct |
18 ms |
3660 KB |
Output is correct |
47 |
Correct |
275 ms |
43460 KB |
Output is correct |
48 |
Correct |
695 ms |
106692 KB |
Output is correct |
49 |
Correct |
151 ms |
29764 KB |
Output is correct |
50 |
Correct |
852 ms |
126788 KB |
Output is correct |
51 |
Correct |
271 ms |
58820 KB |
Output is correct |
52 |
Correct |
703 ms |
110276 KB |
Output is correct |
53 |
Correct |
629 ms |
104800 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
346 ms |
67428 KB |
Output is correct |
56 |
Correct |
389 ms |
76332 KB |
Output is correct |
57 |
Correct |
336 ms |
68932 KB |
Output is correct |
58 |
Correct |
614 ms |
102804 KB |
Output is correct |
59 |
Correct |
310 ms |
63828 KB |
Output is correct |
60 |
Correct |
704 ms |
130372 KB |
Output is correct |
61 |
Correct |
680 ms |
130192 KB |
Output is correct |
62 |
Correct |
785 ms |
129632 KB |
Output is correct |
63 |
Correct |
763 ms |
129780 KB |
Output is correct |
64 |
Correct |
725 ms |
129944 KB |
Output is correct |
65 |
Correct |
616 ms |
130896 KB |
Output is correct |
66 |
Correct |
630 ms |
130656 KB |
Output is correct |
67 |
Correct |
640 ms |
130612 KB |
Output is correct |
68 |
Correct |
305 ms |
79432 KB |
Output is correct |
69 |
Correct |
301 ms |
72776 KB |
Output is correct |
70 |
Correct |
374 ms |
93240 KB |
Output is correct |
71 |
Correct |
456 ms |
98884 KB |
Output is correct |