Submission #60244

#TimeUsernameProblemLanguageResultExecution timeMemory
60244aintaSparklers (JOI17_sparklers)C++17
100 / 100
70 ms12384 KiB
#include<cstdio> #include<algorithm> #define N_ 101000 using namespace std; int n, st, n1, n2, D[N_]; long long T, INF = 1e9, X[N_]; long long A[N_], B[N_], AA[N_], BB[N_]; struct point { int pv; long long Mn, Mx; }w[N_]; bool Do() { int i, cnt = 0; n1--, n2--; long long Mx = -4e18, Mn = 4e18; for (i = 0; i <= n2; i++) { Mn = min(Mn, B[i]); if (Mx <= B[i]) { Mx = B[i]; w[cnt++] = { i,Mn,Mx }; Mn = B[i]; } } for (i = 0; i < cnt; i++) { if (w[i].Mn + A[0] < 0)break; } D[0] = i - 1; if (D[0] == -1)return false; for (i = 1; i <= n1; i++) { if (w[D[i - 1]].Mx + A[i] < 0)return false; int pv = D[i - 1]; while (pv < cnt - 1 && w[pv + 1].Mn + A[i] >= 0)pv++; D[i] = pv; } return w[D[n1]].pv == n2; } bool Pos(long long KK) { long long L = T*KK; if (L >= 1e9)return true; int i, j; for (i = st; i >= 1; i--) { AA[i] = X[i] + L * 2 * (st - i); } for (i = st; i <= n; i++) { BB[i] = -(X[i] - L * 2 * (i - st)); } int pv1 = st, pv2 = st; for (i = st; i >= 1; i--) if (AA[pv1] < AA[i])pv1 = i; for (i = st; i <= n; i++) if (BB[pv2] < BB[i])pv2 = i; n1 = 0, n2 = 0; for (i = st; i >= pv1; i--) A[n1++] = AA[i]; for (i = st; i <= pv2; i++) B[n2++] = BB[i]; if (!Do())return false; n1 = 0, n2 = 0; for (i = 1; i <= pv1; i++) A[n1++] = AA[i]; for (i = n; i >= pv2; i--) B[n2++] = BB[i]; if (!Do())return false; return true; } int main() { int i; scanf("%d%d%lld", &n, &st, &T); for (i = 1; i <= n; i++) { scanf("%lld", &X[i]); } long long b = 0, e = 1e9, mid, res; while (b <= e) { mid = (b + e) / 2; if (Pos(mid)) { res = mid; e = mid - 1; } else b = mid + 1; } printf("%d\n", res); }

Compilation message (stderr)

sparklers.cpp: In function 'bool Pos(long long int)':
sparklers.cpp:40:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sparklers.cpp: In function 'int main()':
sparklers.cpp:78:20: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n", res);
                    ^
sparklers.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%lld", &n, &st, &T);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &X[i]);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...