제출 #699156

#제출 시각아이디문제언어결과실행 시간메모리
699156dooweyNaan (JOI19_naan)C++14
29 / 100
65 ms4664 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = 2010; const ll C = (ll)2e18; ll V[N][N]; struct Frac{ ll A; ll B; Frac operator+(Frac bi){ return {A * bi.B + B * bi.A, B * bi.B}; } Frac operator-(Frac bi){ return {A * bi.B - B * bi.A, B * bi.B}; } Frac operator*(Frac bi){ return {A * bi.A, B * bi.B}; } }; Frac get_sum(int i, Frac en){ Frac g = {0, 1}; int id = (ll)(en.A / en.B); for(int j = 0 ; j < id; j ++ ){ g = g + (Frac){V[i][j], 1}; } g = g + (en - (Frac){id, 1}) * (Frac){V[i][id], 1}; return g; } Frac need[N]; int go[N]; int main(){ fastIO; //freopen("in.txt", "r", stdin); int n, m; cin >> n >> m; for(int i = 1; i <= n; i ++ ){ need[i] = {0, n}; for(int j = 0 ;j < m ; j ++ ){ cin >> V[i][j]; need[i].A += V[i][j]; } go[i] = -1; } Frac las = (Frac){0, 1}; Frac cum; Frac nx; Frac sum; ll C, VV; ll X; Frac low; Frac fin; int id; vector<Frac> ff; for(int iter = 1; iter < n; iter ++ ){ low = {m, 1}; id = -1; for(int i = 1; i <= n; i ++ ){ if(go[i] != -1) continue; cum = get_sum(i, las); nx = (Frac){0, 1}; for(int j = 0; j < m ; j ++ ){ nx = nx + (Frac) {V[i][j], 1}; sum = nx - cum; sum = sum - need[i]; if(sum.A >= 0){ VV = V[i][j]; C = (ll)1e9; sum = sum * (Frac) {C, VV}; X = sum.A / sum.B; fin = (Frac){(j + 1), 1} - (Frac){X, C}; if((low - fin).A > 0){ low = fin; id = i; } break; } } } ff.push_back(low); cout << low.A << " " << low.B << "\n"; go[id] = iter; las = low; } for(int i = 1; i <= n; i ++ ){ if(go[i] == -1) go[i] = n; cout << go[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...