# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
124452 | songc | Naan (JOI19_naan) | C++14 | 220 ms | 255864 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef __int128 LL;
typedef pair<int, int> pii;
int N, K=1, L;
bool chk[2020];
struct Rat{
LL p=1, q=0;
Rat(){}
Rat(LL x, LL y){p = y, q = x;}
Rat operator+(const Rat &r)const{
LL g = __gcd(q*r.p + r.q*p, p*r.p);
return Rat((q*r.p + r.q*p)/g, p*r.p / g);
}
Rat operator-(const Rat &r)const{
LL g = __gcd(q*r.p - r.q*p, p*r.p);
return Rat((q*r.p - r.q*p)/g, (p*r.p)/g);
}
Rat operator*(const Rat &r)const{
LL g = __gcd(q*r.q, p*r.p);
return Rat(q*r.q/g, p*r.p/g);
}
Rat operator/(const Rat &r)const{
LL g = __gcd(q*r.p, p*r.q);
return Rat(q*r.p/g, p*r.q/g);
}
bool operator<(const Rat &r)const{
return q*r.p < r.q*p;
}
} A[2020][2020], C[2020][2020];
int main(){
LL a;
scanf("%d %d", &N, &L);
for (int i=1; i<=N; i++) {
for (int j=1; j<=L; j++) {
scanf("%lld", &a);
A[i][j].q = a;
A[i][0] = A[i][0] + A[i][j];
}
A[i][0].p = N;
}
for (int i=1; i<=N; i++){
Rat R = Rat(0, 1);
for (int j=1; j<=N; j++){
Rat S = A[i][0];
while (1){
Rat x = A[i][R.q/R.p+1] * (Rat(R.q/R.p+1, 1) - R);
if (x < S){
S = S - x;
R = Rat(R.q/R.p+1, 1);
}
else{
R = R + (S / A[i][R.q/R.p+1]);
break;
}
}
C[i][j] = R;
}
}
vector<int> V;
for (int i=1; i<=N; i++){
Rat Min=Rat(L+1, 1);
int id;
for (int j=1; j<=N; j++){
if (chk[j]) continue;
if (C[j][i] < Min){
Min = C[j][i];
id = j;
}
}
if (i<N) printf("%lld %lld\n", (LL)Min.q, (LL)Min.p);
V.push_back(id);
chk[id] = true;
}
for (int x : V) printf("%d ", x);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |