Submission #527501

#TimeUsernameProblemLanguageResultExecution timeMemory
527501idasFancy Fence (CEOI20_fancyfence)C++11
0 / 100
25 ms14280 KiB
#include <bits/stdc++.h> #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define TSTS int ttt; cin >> ttt; while(ttt--) solve() #define all(x) (x).begin(), (x).end() #define le(vec) vec[vec.size()-1] #define sz(x) ((int)((x).size())) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int INF=1e9, MOD=1e9+7, mod=998244353; const ll LINF=1e18; void setIO() { FAST_IO; } void setIO(string s) { FAST_IO; freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const int N=1e3+10; int n; ll h[N], w[N], mn[N][N], sm[N][N]; ll cure(ll x) { while(x<0) x+=MOD; x%=MOD; return x; } int main() { setIO(); cin >> n; FOR(i, 0, n) cin >> h[i]; FOR(i, 0, n) cin >> w[i]; FOR(i, 0, n) { mn[i][i]=h[i]; sm[i][i]=w[i]; sm[i][i]%=MOD; FOR(j, i+1, n) { mn[i][j]=min(h[i], mn[i][j-1]); sm[i][j]=sm[i][j-1]+w[j]; sm[i][j]%=MOD; } } ll ans=0; FOR(i, 0, n) { ans+=(((w[i]+1)*w[i]/2%MOD)*((h[i]+1)*h[i]/2%MOD))%MOD; ans%=MOD; FOR(j, i+1, n) { ll wdt=sm[i][j], hgt=(mn[i][j]+1)*mn[i][j]/2%MOD; ans+=((wdt+1)*wdt/2%MOD)*hgt%MOD; ans+=MOD; ans-=(cure(wdt-w[i]+1)*cure(wdt-w[i])/2%MOD)*hgt%MOD; ans-=(cure(wdt-w[j]+1)*cure(wdt-w[j])/2%MOD)*hgt%MOD; ans+=(cure(wdt-w[i]-w[j]+1)*cure(wdt-w[i]-w[j])/2%MOD)*hgt%MOD; cure(ans); } } cout << ans; }

Compilation message (stderr)

fancyfence.cpp: In function 'void setIO(std::string)':
fancyfence.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...