이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
#define fir first
#define sec second
#define ll long long
#define pii pair<int, int>
const int mxN=2020;
typedef struct frac{
ll ja, mo;
}frac;
ll N, L;
ll V[mxN][mxN];
frac ans[mxN][mxN];
ll sum[mxN];
bool Chk[mxN];
queue <int> que;
bool cmp(frac a, frac b)
{
ll anum=a.ja/a.mo, bnum=b.ja/b.mo;
if(anum!=bnum) return anum<bnum;
a.ja-=anum*a.mo, b.ja-=bnum*b.mo;
return a.ja*b.mo<b.ja*a.mo;
}
int main()
{
gibon
cin >> N >> L;
for(int i=1;i<=N;i++) for(int j=1;j<=L;j++) cin >> V[i][j];
for(int i=1;i<=N;i++) for(int j=1;j<=L;j++) sum[i]+=V[i][j];
for(int i=1;i<=N;i++)
{
ll now=0;
ll cnt=1;
for(int j=1;j<=N;j++)
{
ll tot=sum[i];
while(tot>N*V[i][cnt]-now)
{
tot-=N*V[i][cnt]-now;
now=0;
cnt++;
}
now+=tot;
ans[i][j].mo=N*V[i][cnt];
ans[i][j].ja=now+ans[i][j].mo*(cnt-1);
}
}
for(int i=1;i<N;i++)
{
int pos=-1;
for(int j=1;j<=N;j++)
{
if(Chk[j]) continue;
if(pos==-1) pos=j;
else if(cmp(ans[j][i], ans[pos][i])) pos=j;
}
cout << ans[pos][i].ja << " " << ans[pos][i].mo << '\n';
que.push(pos);
Chk[pos]=true;
}
for(int i=1;i<=N;i++) if(!Chk[i]) que.push(i);
while(!que.empty())
{
cout << que.front() << " ";
que.pop();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |