Submission #784015

#TimeUsernameProblemLanguageResultExecution timeMemory
784015rainboySnail (NOI18_snail)C11
100 / 100
2 ms596 KiB
#include <stdio.h> #define N 10000 #define INF 0x3f3f3f3f3f3f3f3fLL long long min(long long a, long long b) { return a < b ? a : b; } int main() { static long long xx[N + 1], pp[N + 1], qq[N + 1]; int n, i, i_; long long x_, x, k, k_; scanf("%lld%d", &x_, &n); for (i = 1; i <= n; i++) { scanf("%lld", &xx[i]); xx[i] += xx[i - 1]; } for (i = 0; i <= n; i++) pp[i] = min(i == 0 ? INF : pp[i - 1], xx[i]); for (i = n; i >= 0; i--) qq[i] = min(i == n ? INF : qq[i + 1], xx[i]); k_ = INF, i_ = -1; for (i = 1; i <= n; i++) { x = xx[i] - pp[i]; if (x >= x_) { k = 0; if (k_ > k || k_ == k && i_ > i) k_ = k, i_ = i; } else if (xx[n] > 0) { k = (x_ - x + xx[n] - 1) / xx[n]; if (k_ > k || k_ == k && i_ > i) k_ = k, i_ = i; } x = xx[i] - qq[i] + xx[n]; if (x >= x_) { k = 1; if (k_ > k || k_ == k && i_ > i) k_ = k, i_ = i; } else if (xx[n] > 0) { k = (x_ - x + xx[n] - 1) / xx[n] + 1; if (k_ > k || k_ == k && i_ > i) k_ = k, i_ = i; } } if (k_ == INF) printf("-1 -1\n"); else printf("%lld %d\n", k_, i_ - 1); return 0; }

Compilation message (stderr)

snail.c: In function 'main':
snail.c:27:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   27 |    if (k_ > k || k_ == k && i_ > i)
      |                  ~~~~~~~~^~~~~~~~~
snail.c:31:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   31 |    if (k_ > k || k_ == k && i_ > i)
      |                  ~~~~~~~~^~~~~~~~~
snail.c:37:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   37 |    if (k_ > k || k_ == k && i_ > i)
      |                  ~~~~~~~~^~~~~~~~~
snail.c:41:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   41 |    if (k_ > k || k_ == k && i_ > i)
      |                  ~~~~~~~~^~~~~~~~~
snail.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%lld%d", &x_, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
snail.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...