Submission #221863

#TimeUsernameProblemLanguageResultExecution timeMemory
221863patrikpavic2Candies (JOI18_candies)C++17
8 / 100
1010 ms167440 KiB
#include <cstdio> #include <vector> #include <algorithm> #define PB push_back #define X first #define Y second using namespace std; typedef long long ll; typedef pair < int, int > pii; typedef vector < ll > vi; const int N = 3e5 + 500; vi v[N][4]; int cnt = 0, n, A[N]; vi mrg(vi &A, vi &B){ if(!A.size()) return B; if(!B.size()) return A; vi C = {A[0], B[0]}; for(int i = 1;i < (int)A.size();i++) C.PB(A[i] - A[i - 1]); for(int i = 1;i < (int)B.size();i++) C.PB(B[i] - B[i - 1]); sort(C.rbegin(), C.rend()); for(int i = 1;i < (int)C.size();i++) C[i] += C[i - 1]; return C; } vi mks(vi A, vi B){ if(A.size() < B.size()) swap(A, B); vi C = A; for(int i = 0;i < (int)B.size();i++) C[i] = max(C[i], B[i]); return C; } int solve(int l,int r){ if(l == r){ v[cnt][3].PB(A[l]); return cnt++; } int L = solve(l, (l + r) / 2); int R = solve((l + r) / 2 + 1, r); for(int i = 0;i < 4;i++){ for(int j = 0;j < 4;j++){ if((i&2) && (j&1)) continue; v[cnt][(i&1) + (j&2)] = mks(v[cnt][(i&1) + (j&2)], mrg(v[L][i], v[R][j])); } } return cnt++; } int main(){ scanf("%d", &n); for(int i = 0;i < n;i++) scanf("%d", A + i); int kraj = solve(0, n - 1); vi fin = mks(mks(v[kraj][0], v[kraj][1]), mks(v[kraj][2], v[kraj][3])); for(ll x : fin) printf("%lld\n", x); }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
candies.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A + i); 
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...