Submission #209515

# Submission time Handle Problem Language Result Execution time Memory
209515 2020-03-14T12:30:35 Z model_code Snail (NOI18_snail) C++17
100 / 100
8 ms 380 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
ll H, N, A[MAXN];
__int128 sum;
int main() {
	scanf("%lld%lld", &H, &N);
	for (int i = 0; i < N; ++i) {
		scanf("%lld", &A[i]);
		sum += A[i];
		sum = max((__int128) 0, sum);
		if (sum >= H) {
			printf("0 %d\n", i);
			return 0;
		}
	}
	if (sum == 0) {
		puts("-1 -1");
		return 0;
	}
	__int128 d1 = sum;
	__int128 high = sum;
	for (int i = 0; i < N; ++i) {
		sum += A[i];
		sum = max((__int128) 0, sum);
		high = max(sum, high);
		if (sum >= H) {
			printf("1 %d\n", i);
			return 0;
		}
	}
	__int128 d2 = sum;
	if (d1 >= d2) {
		puts("-1 -1");
		return 0;
	}
	__int128 step = d2 - d1;
	long long days = (H-high+step-1)/step;
	__int128 left = H-(days*step)-d1;
	if (left == 0) {
		printf("%lld %d\n", days, N-1);
		return 0;
	}
	for (int i = 0; i < N; ++i) {
		left -= A[i];
		if (left <= 0) {
			printf("%lld %d\n", days+1, i);
			return 0;
		}
	}
}

Compilation message

snail.cpp: In function 'int main()':
snail.cpp:42:32: warning: format '%d' expects argument of type 'int', but argument 3 has type 'll {aka long long int}' [-Wformat=]
   printf("%lld %d\n", days, N-1);
                             ~~~^
snail.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &H, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
snail.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &A[i]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
# 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 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 8 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct