Submission #283165

# Submission time Handle Problem Language Result Execution time Memory
283165 2020-08-25T10:46:52 Z cgiosy Akvizna (COCI19_akvizna) C++17
130 / 130
56 ms 2424 KB
#pragma GCC optimize("Ofast")
#include <cstdio>
struct fn {
	double x;
	int j, c;
};
int cr(fn& a, fn& b) { return a.x!=b.x ? (a.j-b.j)/(a.x-b.x) : 0; }
int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	double l=0, r=1+1e-10;

	int C[N+1];
	fn D[N+1];
	D[0]={};
	while(1) {
		bool last=r-l<1e-10;
		auto m=(l+r)/2;
		int k=0, s=0, e=0;
		C[0]=N;
		for(int i=1; i<=N && (last || k<=K); i++) {
			while(C[s]<i) s++;
			fn t{D[s].x+double(i-D[s].j)/i-m, i, k=D[s].c+1};
			while(s<e && C[e-1]>=(C[e]=cr(D[e], t))) e--;
			if(s==e) C[e]=cr(D[e], t);
			D[++e]=t, C[e]=N;
		}
		if(k==K || last) return!printf("%.9lf", D[e].x+K*m);
		(k>K?l:r)=m;
	}
}

Compilation message

akvizna.cpp: In function 'int main()':
akvizna.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 416 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2144 KB Output is correct
2 Correct 48 ms 2176 KB Output is correct
3 Correct 46 ms 2120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2168 KB Output is correct
2 Correct 49 ms 2176 KB Output is correct
3 Correct 48 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2048 KB Output is correct
2 Correct 50 ms 2292 KB Output is correct
3 Correct 50 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2296 KB Output is correct
2 Correct 48 ms 2176 KB Output is correct
3 Correct 47 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2168 KB Output is correct
2 Correct 49 ms 2296 KB Output is correct
3 Correct 50 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2296 KB Output is correct
2 Correct 48 ms 2176 KB Output is correct
3 Correct 48 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2168 KB Output is correct
2 Correct 46 ms 2132 KB Output is correct
3 Correct 47 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2168 KB Output is correct
2 Correct 56 ms 2296 KB Output is correct
3 Correct 46 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2176 KB Output is correct
2 Correct 48 ms 2176 KB Output is correct
3 Correct 50 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2176 KB Output is correct
2 Correct 46 ms 2176 KB Output is correct
3 Correct 49 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2424 KB Output is correct
2 Correct 49 ms 2296 KB Output is correct
3 Correct 50 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2296 KB Output is correct
2 Correct 53 ms 2296 KB Output is correct
3 Correct 53 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2296 KB Output is correct
2 Correct 51 ms 2296 KB Output is correct
3 Correct 54 ms 2296 KB Output is correct