# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873363 |
2023-11-14T23:25:09 Z |
ofrankel |
Naan (JOI19_naan) |
C++17 |
|
672 ms |
163676 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll __int128_t
int n,l;
vector<vector<int>>v;
ll gc(ll a,ll b){
if(!b)return a;
return gc(b,a%b);
}
class frac{
public:
ll a,b;
frac(ll _a,ll _b):a(_a),b(_b){reduce();}
frac(ll x):a(x),b(1){}
void reduce(){if(ll g=gc(a,b)){a/=g;b/=g;}}
bool operator <(const frac& other){return a*other.b<other.a*b;}
frac operator +( const frac& other){return frac(a*other.b+b*other.a,b*other.b);}
};
pair<vector<pair<ll,ll>>,vector<int>> solve(int N,int L,vector<vector<int>>V){
n=N;l=L;v=move(V);
vector<int>was(n);
vector<int>p(n);
vector<pair<ll,ll>>t(n-1);
vector<ll>s(n);for(int i=0;n>i;++i)for(int j:v[i])s[i]+=j;
vector<vector<frac>>g(n,vector<frac>(n-1,l));
for(int i=0;n>i;++i){
int ind=0;ll kam=0;
for(int j=0;n>j+1;++j){
if(v[i][ind]*n>=kam+s[i]){
g[i][j]=frac((ll)v[i][ind]*n*ind+kam+s[i],v[i][ind]*n);
kam+=s[i];}
else{
int nishar=s[i]+kam-v[i][ind]*n;
while(nishar>v[i][++ind]*n){nishar-=v[i][ind]*n;}
kam=nishar;
g[i][j]=frac((ll)v[i][ind]*n*ind+kam,v[i][ind]*n);}
}
}
for(int i=0;n>i+1;++i){frac cur(l);int ind=0;for(int j=0;n>j;++j)if(!was[j]&&g[j][i]<cur){cur=g[j][i];ind=j;}t[i]={cur.a,cur.b};was[ind]=1;p[i]=ind+1;}
for(int i=0;n>i;++i)if(!was[i])p[n-1]=i+1;
return {t,p};
}
int main()
{
std::ios::sync_with_stdio(0);cin.tie(0);
int N,L;cin>>N>>L;
vector<vector<int>>V(N,vector<int>(L));
for(auto&i:V)for(auto&j:i)cin>>j;
auto [t,p]=solve(N,L,move(V));
if(t.size()==0&&p.size()==0)
cout<<-1<<endl;
else{
for(auto [a,b]:t)
cout<<(long long)a<<" "<<(long long)b<<"\n";
for(int i:p)
cout<<i<<" ";
cout<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
53 ms |
11356 KB |
Output is correct |
44 |
Correct |
327 ms |
65588 KB |
Output is correct |
45 |
Correct |
132 ms |
28048 KB |
Output is correct |
46 |
Correct |
13 ms |
2644 KB |
Output is correct |
47 |
Correct |
198 ms |
44256 KB |
Output is correct |
48 |
Correct |
450 ms |
115832 KB |
Output is correct |
49 |
Correct |
99 ms |
26964 KB |
Output is correct |
50 |
Correct |
566 ms |
137812 KB |
Output is correct |
51 |
Correct |
193 ms |
44880 KB |
Output is correct |
52 |
Correct |
470 ms |
112088 KB |
Output is correct |
53 |
Correct |
453 ms |
103260 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
210 ms |
63176 KB |
Output is correct |
56 |
Correct |
274 ms |
65876 KB |
Output is correct |
57 |
Correct |
220 ms |
56020 KB |
Output is correct |
58 |
Correct |
382 ms |
102740 KB |
Output is correct |
59 |
Correct |
222 ms |
52120 KB |
Output is correct |
60 |
Correct |
575 ms |
163300 KB |
Output is correct |
61 |
Correct |
594 ms |
163156 KB |
Output is correct |
62 |
Correct |
672 ms |
162788 KB |
Output is correct |
63 |
Correct |
635 ms |
163676 KB |
Output is correct |
64 |
Correct |
635 ms |
163600 KB |
Output is correct |
65 |
Correct |
616 ms |
150100 KB |
Output is correct |
66 |
Correct |
607 ms |
150272 KB |
Output is correct |
67 |
Correct |
554 ms |
150224 KB |
Output is correct |
68 |
Correct |
230 ms |
72804 KB |
Output is correct |
69 |
Correct |
224 ms |
64860 KB |
Output is correct |
70 |
Correct |
296 ms |
91600 KB |
Output is correct |
71 |
Correct |
363 ms |
102736 KB |
Output is correct |