이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define X first
#define Y second
const pll INF = {1e9, 1};
int N, L, V[2009][2009], A[2009];
pll D[2009][2009];
bool operator <(pll P, pll Q) {
return 1LL * P.X * Q.Y < 1LL * Q.X * P.Y;
}
pll f(ll a, ll b) {
ll gcd = __gcd(a, b);
return {a / gcd, b / gcd};
}
void R(int i) {
ll a, b, sa = 0, sb = 1;
tie(sa, sb) = f(sa, sb);
int k = 1;
for(int j=0; j<L; j++) {
// sa / sb + V[i][j] >= A[i] / N * k
if(1LL * sa * N + 1LL * V[i][j] * sb * N >= 1LL * A[i] * sb * k) {
// (a / b) * V[i][j] + (sa / sb) == A[i] / N * k
// a/b * V[i][j] * sb * N + sa * N == A[i] * sb * k
// a/b * V[i][j] * sb * N == A[i] * sb * k - sa * N;
b = 1LL * V[i][j] * sb * N;
a = 1LL * b * j + 1LL * A[i] * sb * k - 1LL * sa * N;
D[i][k] = f(a, b);
++k;
}
sa += 1LL * sb * V[i][j];
tie(sa, sb) = f(sa, sb);
}
while(k <= N) D[i][k++] = {L, 1};
}
bool chk[2009];
int main() {
scanf("%d%d",&N,&L);
for(int i=1; i<=N; i++) {
for(int j=0; j<L; j++) {
scanf("%d",&V[i][j]);
A[i] += V[i][j];
}
R(i);
}
vector<pll> pos; vector<int> P;
for(int i=1; i<=N; i++) {
pll mn = INF; int mni = -1;
for(int j=1; j<=N; j++) if(!chk[j]) {
if(D[j][i] < mn) {
mn = D[j][i];
mni = j;
}
}
pos.push_back(mn);
P.push_back(mni);
chk[mni] = 1;
}
for(int i=0; i<N-1; i++) printf("%lld %lld\n", pos[i].X, pos[i].Y);
for(auto& it: P) printf("%d ", it);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
naan.cpp: In function 'int main()':
naan.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&L);
~~~~~^~~~~~~~~~~~~~
naan.cpp:48:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&V[i][j]);
~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |