# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873351 |
2023-11-14T21:58:38 Z |
ofrankel |
Naan (JOI19_naan) |
C++17 |
|
1 ms |
600 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
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(int 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<int,int>>,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<int,int>>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){
frac cur(0);
for(int j=0;n>j+1;++j){
int c=cur.a/cur.b;
frac cc((c+1)*cur.b-cur.a,cur.b);
if(cc.a*n*v[i][c]>=cc.b*s[i]){
cur=cur+frac(s[i],v[i][c]*n);
g[i][j]=cur;
}
else{
ll cb=cur.b;
ll cl=s[i]*cur.b;
ll ck=cc.a*v[i][c];
int j1=c+1;
while(l>j1&&(ck+v[i][j1]*cb)*n<cl){ck+=v[i][j1]*cb;++j;}
if(j1==l)continue;
ll tt=cl-ck*n;
frac tmp=frac(tt,n*cb*v[i][j1])+cc+frac(j1-c-1);
cur=cur+tmp;
g[i][j]=cur;
}
}
}
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<<a<<" "<<b<<"\n";
for(int i:p)
cout<<i<<" ";
cout<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
X_i is not increasing |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |