답안 #533387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533387 2022-03-05T20:46:58 Z pooyashams Naan (JOI19_naan) C++17
29 / 100
180 ms 66952 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int inf = 1e9;

ll nbsct(ll a, ll b)
{
	ld r = (1.0l*a/b) * inf;
	return floor(r+.5);
}

struct mfint
{
	ll a, b; // a/b
	mfint()
	{
		a = 1;
		b = 1;
	}
	mfint(ll _a)
	{
		a = _a;
		b = 1;
	}
	mfint(ll _a, ll _b)
	{
		a = _a;
		b = _b;
	}
	inline void simp()
	{
		ll x = __gcd(a, b);
		a /= x;
		b /= x;
		if(b > inf)
		{
			a = nbsct(a, b);
			b = inf;
		}
	}
	inline ll floor()
	{
		return a/b;
	}
	inline ll ceil()
	{
		return (a+b-1)/b;
	}
	inline mfint operator+(mfint y)
	{
		mfint x;
		x.b = b*y.b;
		x.a = a*y.b + b*y.a;
		x.simp();
		return x;
	}
	inline mfint operator-(mfint y)
	{
		mfint x;
		x.b = b*y.b;
		x.a = a*y.b - b*y.a;
		x.simp();
		return x;
	}
	inline mfint operator*(mfint y)
	{
		mfint x;
		x.a = a*y.a;
		x.b = b*y.b;
		x.simp();
		return x;
	}
	inline mfint operator/(mfint y)
	{
		mfint x;
		x.a = a*y.b;
		x.b = b*y.a;
		x.simp();
		return x;
	}
	inline bool operator<(mfint y)
	{
		return a*y.b < b*y.a;
	}
	inline bool operator<=(mfint y)
	{
		return a*y.b <= b*y.a;
	}
	inline bool operator>(mfint y)
	{
		return a*y.b > b*y.a;
	}
	inline bool operator>=(mfint y)
	{
		return a*y.b >= b*y.a;
	}
	inline bool operator==(mfint y)
	{
		return a*y.b == b*y.a;
	}
};

const int maxn = 2012;

int vals[maxn][maxn];
mfint vmf[maxn][maxn];
mfint avgs[maxn];

int n, L;

inline mfint nxtf(int i, mfint f)
{
	mfint a = avgs[i];
	int xv = f.floor();
	mfint x = mfint(xv);
	mfint res;
	res = vmf[i][xv] * (res-f+x);
	if(res >= a)
		return f+(a/vmf[i][xv]);
	a = a-res;
	xv++;
	while(xv < L)
	{
		if(vmf[i][xv] >= a)
			return mfint(xv) + (a/vmf[i][xv]);
		else
			a = a-vmf[i][xv];
		xv++;
	}
	return mfint(L);
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> L;
	for(int i = 0; i < n; i++)
	{
		int s = 0;
		for(int j = 0; j < L; j++)
		{
			cin >> vals[i][j];
			vmf[i][j] = mfint(vals[i][j]);
			s += vals[i][j];
		}
		avgs[i] = mfint(s, n);
	}
	vector<mfint> divs;
	vector<int> prm;
	vector<int> rems(n);
	iota(rems.begin(), rems.end(), 0);
	mfint lf(0);
	for(int i = 0; i < n; i++)
	{
		mfint bst = nxtf(rems[0], lf);
		int bid = rems[0];
		for(int j: rems)
		{
			mfint enf = nxtf(j, lf);
			if(enf <= bst)
			{
				bst = enf;
				bid = j;
			}
		}
		lf = bst;
		divs.push_back(bst);
		prm.push_back(bid);
		rems.erase(find(rems.begin(), rems.end(), bid));
	}
	divs.pop_back();
	for(auto x: divs)
		cout << (long long)(x.a) << " " << (long long)(x.b) << endl;
	for(int i: prm)
		cout << i+1 << " ";
	cout << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 63692 KB Output is correct
2 Correct 25 ms 63712 KB Output is correct
3 Correct 25 ms 63644 KB Output is correct
4 Correct 25 ms 63680 KB Output is correct
5 Correct 28 ms 63632 KB Output is correct
6 Correct 30 ms 63636 KB Output is correct
7 Correct 28 ms 63652 KB Output is correct
8 Correct 27 ms 63732 KB Output is correct
9 Correct 25 ms 63692 KB Output is correct
10 Correct 26 ms 63692 KB Output is correct
11 Correct 27 ms 63660 KB Output is correct
12 Correct 27 ms 63708 KB Output is correct
13 Correct 26 ms 63648 KB Output is correct
14 Correct 26 ms 63612 KB Output is correct
15 Correct 28 ms 63652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 63684 KB Output is correct
2 Correct 25 ms 63684 KB Output is correct
3 Correct 26 ms 63692 KB Output is correct
4 Correct 26 ms 63728 KB Output is correct
5 Correct 26 ms 63736 KB Output is correct
6 Correct 29 ms 63684 KB Output is correct
7 Correct 27 ms 63692 KB Output is correct
8 Correct 27 ms 63692 KB Output is correct
9 Correct 27 ms 63724 KB Output is correct
10 Correct 26 ms 63720 KB Output is correct
11 Correct 26 ms 63712 KB Output is correct
12 Correct 25 ms 63608 KB Output is correct
13 Correct 27 ms 63692 KB Output is correct
14 Correct 27 ms 63740 KB Output is correct
15 Correct 27 ms 63648 KB Output is correct
16 Correct 26 ms 63692 KB Output is correct
17 Correct 26 ms 63704 KB Output is correct
18 Correct 26 ms 63760 KB Output is correct
19 Correct 28 ms 63676 KB Output is correct
20 Correct 25 ms 63628 KB Output is correct
21 Correct 26 ms 63776 KB Output is correct
22 Correct 26 ms 63740 KB Output is correct
23 Correct 26 ms 63684 KB Output is correct
24 Correct 26 ms 63656 KB Output is correct
25 Correct 26 ms 63728 KB Output is correct
26 Correct 26 ms 63632 KB Output is correct
27 Correct 26 ms 63652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 63692 KB Output is correct
2 Correct 25 ms 63712 KB Output is correct
3 Correct 25 ms 63644 KB Output is correct
4 Correct 25 ms 63680 KB Output is correct
5 Correct 28 ms 63632 KB Output is correct
6 Correct 30 ms 63636 KB Output is correct
7 Correct 28 ms 63652 KB Output is correct
8 Correct 27 ms 63732 KB Output is correct
9 Correct 25 ms 63692 KB Output is correct
10 Correct 26 ms 63692 KB Output is correct
11 Correct 27 ms 63660 KB Output is correct
12 Correct 27 ms 63708 KB Output is correct
13 Correct 26 ms 63648 KB Output is correct
14 Correct 26 ms 63612 KB Output is correct
15 Correct 28 ms 63652 KB Output is correct
16 Correct 26 ms 63684 KB Output is correct
17 Correct 25 ms 63684 KB Output is correct
18 Correct 26 ms 63692 KB Output is correct
19 Correct 26 ms 63728 KB Output is correct
20 Correct 26 ms 63736 KB Output is correct
21 Correct 29 ms 63684 KB Output is correct
22 Correct 27 ms 63692 KB Output is correct
23 Correct 27 ms 63692 KB Output is correct
24 Correct 27 ms 63724 KB Output is correct
25 Correct 26 ms 63720 KB Output is correct
26 Correct 26 ms 63712 KB Output is correct
27 Correct 25 ms 63608 KB Output is correct
28 Correct 27 ms 63692 KB Output is correct
29 Correct 27 ms 63740 KB Output is correct
30 Correct 27 ms 63648 KB Output is correct
31 Correct 26 ms 63692 KB Output is correct
32 Correct 26 ms 63704 KB Output is correct
33 Correct 26 ms 63760 KB Output is correct
34 Correct 28 ms 63676 KB Output is correct
35 Correct 25 ms 63628 KB Output is correct
36 Correct 26 ms 63776 KB Output is correct
37 Correct 26 ms 63740 KB Output is correct
38 Correct 26 ms 63684 KB Output is correct
39 Correct 26 ms 63656 KB Output is correct
40 Correct 26 ms 63728 KB Output is correct
41 Correct 26 ms 63632 KB Output is correct
42 Correct 26 ms 63652 KB Output is correct
43 Incorrect 180 ms 66952 KB Integer parameter [name=A_i] equals to -165120039426, violates the range [1, 2000000000000]
44 Halted 0 ms 0 KB -