제출 #410195

#제출 시각아이디문제언어결과실행 시간메모리
410195amoo_safarNaan (JOI19_naan)C++17
29 / 100
242 ms49716 KiB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

typedef pll frac;

bool CMP(frac A, frac B){
	return A.F * B.S < A.S * B.F;
}
ll V[N];
vector<frac> cut[N];
int mk[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, L;
	cin >> n >> L;

	for(int p = 0; p < n; p++){
		ll sm = 0;
		for(int i = 0; i < L; i++){
			cin >> V[i];
			sm += V[i];
		}
		int po = 0;
		ll smnw = 0;
		for(int it = 1; it < n; it ++){
			while(n * (V[po] + smnw) <= sm * it){
				smnw += V[po];
				po ++;
			}
			frac alp = frac(it * sm - smnw * n, n * V[po]); 
			frac bet = frac(alp.F + po * alp.S, alp.S);
			cut[p].pb(bet);
		}
		// cerr << p << " : ";
		// for(auto [up, dw] : cut[p]) cerr << up << "/" << dw << '\n';
		// cerr << '\n';
	}
	vector<int> P;
	for(int i = 0; i < n - 1; i++){
		int idx = -1;
		for(int j = 0; j < n; j++){
			if(mk[j])continue;
			if(idx == -1) idx = j;
			if(CMP(cut[j][i], cut[idx][i]))
				idx = j;
		}
		mk[idx] = 1;
		cout << cut[idx][i].F << ' ' << cut[idx][i].S << '\n';
		P.pb(idx + 1);
	}
	for(int i = 0; i < n; i++) if(!mk[i]) P.pb(i + 1);
	for(auto x : P) cout << x << ' ';
	cout << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...