Submission #203667

# Submission time Handle Problem Language Result Execution time Memory
203667 2020-02-21T19:21:41 Z ics0503 Naan (JOI19_naan) C++17
24 / 100
7 ms 504 KB
#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
set<long long >people;
struct xy { int x; double y; }L[2121];
double need[2121];
long long v[2121][2121], S[2121][2121];
long long gcd(long long a, long long b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
vector<long long>aa, ab;
vector<int>ans;
int main() {
	long long n, l, i, j; scanf("%lld%lld", &n, &l);
	for (i = 1; i <= n; i++)people.insert(i);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= l; j++)scanf("%lld", &v[i][j]);
		long long gg = v[i][1];
		for (j = 1; j <= l; j++)gg = gcd(gg, v[i][j]);
		for (j = 1; j <= l; j++) {
			v[i][j] /= gg; S[i][j] = S[i][j - 1] + v[i][j];
			need[i] += v[i][j];
		}
		need[i] /= n;
	}
	long long befa = 1;double p = 0;
	bool flag = 1;
	for (i = 1; i <= n - 1; i++) {
		long long mnx = 1e9;double mny; long long mnw;
		for (long long who : people) {
			if ((double)(1-p) * (double)v[who][befa] > need[who]) {
				L[who].x = befa;
				L[who].y = p + need[who] / (double)v[who][befa];
			}
			else {
				while ((double)(1 - p) *  (double)v[who][befa] + (double)(S[who][L[who].x] - S[who][befa]) <= need[who]) {
					L[who].x++;
				}
				L[who].y = (double)(need[who] - (double)(1 - p) *  (double)v[who][befa] - (double)(S[who][L[who].x - 1] - S[who][befa])) / (double)v[who][L[who].x];
			}
			if (mnx > L[who].x || (mnx == L[who].x && mny > L[who].y)) {
				mnx = L[who].x;
				mny = L[who].y;
				mnw = who;
			}
		}
		int cnt = 0, ccnt = 0;
		for (long long who : people) {
			if (L[who].x == L[mnw].x && L[who].y == L[mnw].y)cnt++;
			ccnt++;
		}
		if (cnt != ccnt)flag = 0;
		befa = L[mnw].x, p = L[mnw].y + 1e-9;
		long long gj = 1e9;
		long long g = befa*gj + p*gj;
		aa.push_back(g); ab.push_back(gj);
		people.erase(mnw);
		ans.push_back(mnw);
		L[mnw] = { 0, 0 };
	}
	if (flag) {
		for (i = 1; i <= n - 1; i++) {
			printf("%lld %lld\n", i*l, n);
		}
		for (i = 1; i <= n; i++)printf("%d ", i);
		puts("");
		return 0;
	}
	for (int i = 0; i < aa.size(); i++)printf("%lld %lld\n", aa[i], ab[i]);
	for (int i = 0; i < ans.size(); i++)printf("%d ", ans[i]);
	printf("%lld", *people.begin());
	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:67:42: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   for (i = 1; i <= n; i++)printf("%d ", i);
                                          ^
naan.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < aa.size(); i++)printf("%lld %lld\n", aa[i], ab[i]);
                  ~~^~~~~~~~~~~
naan.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++)printf("%d ", ans[i]);
                  ~~^~~~~~~~~~~~
naan.cpp:16:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  long long n, l, i, j; scanf("%lld%lld", &n, &l);
                        ~~~~~^~~~~~~~~~~~~~~~~~~~
naan.cpp:19:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (j = 1; j <= l; j++)scanf("%lld", &v[i][j]);
                           ~~~~~^~~~~~~~~~~~~~~~~~
naan.cpp:31:45: warning: 'mnw' may be used uninitialized in this function [-Wmaybe-uninitialized]
   long long mnx = 1e9;double mny; long long mnw;
                                             ^~~
naan.cpp:43:43: warning: 'mny' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (mnx > L[who].x || (mnx == L[who].x && mny > L[who].y)) {
                          ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Not a fair distribution.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Not a fair distribution.
2 Halted 0 ms 0 KB -