Submission #945604

#TimeUsernameProblemLanguageResultExecution timeMemory
945604itslqFancy Fence (CEOI20_fancyfence)C++17
12 / 100
6 ms500 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; int md(int x) { if (x < 0) return (x % MOD) + MOD; if (x < MOD) return x; return x % MOD; } signed main() { int N, minH, ans = 0, S = 0; bool st3 = 1, st4 = 1, st5 = 1; cin >> N; vector<int> H(N), W(N); for (int i = 0; i < N; i++) { cin >> H[i]; if (H[i] > 2) st3 = 0; if (H[i] != H[0]) st4 = 0; if (i && H[i] < H[i - 1]) st5 = 0; } for (int i = 0; i < N; i++) { cin >> W[i]; S += W[i]; } if (st3) { vector<int> compH{H[0]}, compW{W[0]}; for (int i = 1; i < N; i++) { if (H[i] == compH.back()) compW.back() += W[i]; else { compH.push_back(H[i]); compW.push_back(W[i]); } } if (S % 2) ans = md(S * ((S + 1) / 2)); else ans = md((S / 2) * (S + 1)); for (int i = 0; i < (signed) compH.size(); i++) { if (H[i] == 2) { ans = md(ans + compW[i] * (compW[i] + 1) / 2); } } cout << ans; return 0; } if (N <= 1000) { for (int i = 0; i < N; i++) { minH = H[i]; ans = md(ans + md(H[i] * (H[i] + 1) / 2) * md(W[i] * (W[i] + 1) / 2)); for (int j = i + 1; j < N; j++) { minH = min(minH, H[j]); ans = md(ans + md(W[i] * W[j]) * md(minH * (minH + 1) / 2)); } } cout << ans; } }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:16:19: warning: variable 'st4' set but not used [-Wunused-but-set-variable]
   16 |     bool st3 = 1, st4 = 1, st5 = 1;
      |                   ^~~
fancyfence.cpp:16:28: warning: variable 'st5' set but not used [-Wunused-but-set-variable]
   16 |     bool st3 = 1, st4 = 1, st5 = 1;
      |                            ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...