//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pll pair<ll,ll>
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
bool les(pair<ll,ll> a,pair<ll,ll> b){
return (__int128)a.f*b.s<(__int128)a.s*b.f;
}
void sir(pair<ll,ll> &x){
ll g=__gcd(x.f,x.s);
x.f/=g;
x.s/=g;
}
signed main() {_
int n,l;
cin>>n>>l;
vector<vector<int>> v0(n,vector<int>(l));
vector<vector<ll>> v(n,vector<ll>(l));
vector<int> sum(n);
for(int i=0;i<n;i++){
for(int j=0;j<l;j++){
cin>>v0[i][j];
sum[i]+=v0[i][j];
v[i][j]=v0[i][j]*n;
}
}
vector<vector<pair<ll,ll>>> cut(n,vector<pair<ll,ll>>(n));
for(int i=0;i<n;i++){
int pos=0;
ll rem=v[i][0];
for(int j=0;j<n-1;j++){
ll now=sum[i];
while(pos<l and rem<=now){
now-=rem;
pos++;
rem=v[i][pos];
}
rem-=now;
cut[i][j]={v[i][pos]*(pos+1)-rem,v[i][pos]};
sir(cut[i][j]);
//cout<<cut[i][j].f<<'/'<<cut[i][j].s<<' ';
}
//cout<<'\n';
}
vector<bool> used(n);
vector<int> ans;
for(int i=0;i<n;i++){
int mn=-1;
for(int j=0;j<n;j++){
if(used[j]) continue;
if(mn==-1) mn=j;
else if(les(cut[j][i],cut[mn][i])){
mn=j;
}
}
ans.push_back(mn);
used[mn]=true;
}
for(int i=0;i<n-1;i++){
cout<<cut[ans[i]][i].f<<' '<<cut[ans[i]][i].s<<'\n';
}
for(int i=0;i<n;i++){
cout<<ans[i]+1<<' ';
}
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message
naan.cpp: In function 'void setIO(std::string)':
naan.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
naan.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
612 KB |
Output is correct |
11 |
Correct |
1 ms |
356 KB |
Output is correct |
12 |
Correct |
0 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
356 KB |
Output is correct |
14 |
Correct |
1 ms |
612 KB |
Output is correct |
15 |
Correct |
1 ms |
612 KB |
Output is correct |
16 |
Correct |
1 ms |
612 KB |
Output is correct |
17 |
Correct |
1 ms |
644 KB |
Output is correct |
18 |
Correct |
1 ms |
612 KB |
Output is correct |
19 |
Correct |
1 ms |
612 KB |
Output is correct |
20 |
Correct |
1 ms |
424 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
0 ms |
352 KB |
Output is correct |
23 |
Correct |
0 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
620 KB |
Output is correct |
25 |
Correct |
1 ms |
612 KB |
Output is correct |
26 |
Correct |
1 ms |
356 KB |
Output is correct |
27 |
Correct |
0 ms |
356 KB |
Output is correct |
28 |
Correct |
1 ms |
356 KB |
Output is correct |
29 |
Correct |
1 ms |
612 KB |
Output is correct |
30 |
Correct |
1 ms |
612 KB |
Output is correct |
31 |
Correct |
1 ms |
612 KB |
Output is correct |
32 |
Correct |
1 ms |
644 KB |
Output is correct |
33 |
Correct |
1 ms |
612 KB |
Output is correct |
34 |
Correct |
1 ms |
612 KB |
Output is correct |
35 |
Correct |
1 ms |
424 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
50 ms |
10568 KB |
Output is correct |
44 |
Correct |
325 ms |
61780 KB |
Output is correct |
45 |
Correct |
126 ms |
31868 KB |
Output is correct |
46 |
Correct |
14 ms |
4444 KB |
Output is correct |
47 |
Correct |
190 ms |
41880 KB |
Output is correct |
48 |
Correct |
427 ms |
70228 KB |
Output is correct |
49 |
Correct |
98 ms |
20828 KB |
Output is correct |
50 |
Correct |
520 ms |
104528 KB |
Output is correct |
51 |
Correct |
207 ms |
46780 KB |
Output is correct |
52 |
Correct |
455 ms |
101460 KB |
Output is correct |
53 |
Correct |
408 ms |
83120 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
198 ms |
34172 KB |
Output is correct |
56 |
Correct |
262 ms |
63556 KB |
Output is correct |
57 |
Correct |
214 ms |
51536 KB |
Output is correct |
58 |
Correct |
371 ms |
79184 KB |
Output is correct |
59 |
Correct |
228 ms |
55660 KB |
Output is correct |
60 |
Correct |
550 ms |
136992 KB |
Output is correct |
61 |
Correct |
640 ms |
137328 KB |
Output is correct |
62 |
Correct |
647 ms |
136376 KB |
Output is correct |
63 |
Correct |
586 ms |
137132 KB |
Output is correct |
64 |
Correct |
600 ms |
137176 KB |
Output is correct |
65 |
Correct |
606 ms |
130380 KB |
Output is correct |
66 |
Correct |
695 ms |
130672 KB |
Output is correct |
67 |
Correct |
546 ms |
130424 KB |
Output is correct |
68 |
Correct |
214 ms |
59704 KB |
Output is correct |
69 |
Correct |
350 ms |
62440 KB |
Output is correct |
70 |
Correct |
254 ms |
70608 KB |
Output is correct |
71 |
Correct |
328 ms |
93848 KB |
Output is correct |