Submission #447080

#TimeUsernameProblemLanguageResultExecution timeMemory
447080YahliFancy Fence (CEOI20_fancyfence)C++14
58 / 100
265 ms262148 KiB
#include <bits/stdc++.h> #define int long long using namespace std; using pi = pair<int, int>; const int mod = 1e9+7; const int inv4 = 25e7+2; int calc(int a, int b){ return ((a*(a+1)%mod)*(b*(b+1)%mod)%mod)*inv4%mod; } int req_solve(const vector<pi> & data, int n, int floor){ if (n == 0) return 0; //find the minimum: int ind = 0, w = 0; for (int i = 0; i < n; ++i){ if (data[i].first < data[ind].first) ind = i; w += data[i].second; } w %= mod; int res = (calc(data[ind].first, w) - calc(floor, w) + mod) % mod; vector<pi> next; for (int i = 0; i < n; ++i){ if (data[i].first == data[ind].first){ res = (req_solve(next, next.size(), data[ind].first) + res) % mod; next.resize(0); } else next.push_back(data[i]); } return (req_solve(next, next.size(), data[ind].first) + res) % mod; } int32_t main(){ int n; cin >> n; vector<pi> data(n); for (int i = 0; i < n; ++i) cin >> data[i].first; for (int i = 0; i < n; ++i) cin >> data[i].second; cout << req_solve(data, n, 0); }
#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...