제출 #532158

#제출 시각아이디문제언어결과실행 시간메모리
53215879brueBoat (APIO16_boat)C++14
9 / 100
11 ms564 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; ll mpow(ll x, ll y){ if(!y) return 1; if(y&1) return (mpow(x, y-1)*x)%MOD; ll tmp = mpow(x, y/2); return (tmp*tmp)%MOD; } int n; int a[502], b[502]; map<int, int> idx; vector<int> renumber; ll DP[1002], DPsum[1002]; ll DP2[1002][1002]; ll modInv[1002]; ll ans; int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ scanf("%d %d", &a[i], &b[i]); b[i]++; renumber.push_back(a[i]); renumber.push_back(b[i]); } sort(renumber.begin(), renumber.end()); renumber.erase(unique(renumber.begin(), renumber.end()), renumber.end()); for(int i=0; i<(int)renumber.size(); i++){ idx[renumber[i]] = i; } for(int i=1; i<=1000; i++){ modInv[i] = mpow(i, MOD-2); } DP[0] = 1; for(int i=1; i<(int)renumber.size(); i++){ int s = renumber[i-1], e = renumber[i]; DPsum[0] = 1; vector<int> tv; for(int j=1; j<=n; j++){ DPsum[j] = (DPsum[j-1] + DP[j]) % MOD; if(a[j] <= s && e <= b[j]) tv.push_back(j); } for(int j=1; j<=(int)tv.size() && j<=e-s; j++){ for(int k=j-1; k<(int)tv.size(); k++){ if(j==1){ DP2[j][k] = DPsum[tv[k]-1]*(e-s); if(k!=0) DP2[j][k] += DP2[j][k-1]; DP2[j][k]%=MOD; } else{ DP2[j][j] = ((DP2[j-1][k-1] * modInv[j]) % MOD) * ((e-s+1) - i) + DP2[j][k-1]; DP2[j][k]%=MOD; } } } for(int j=1; j<=(int)tv.size() && j<=e-s; j++){ for(int k=j-1; k<(int)tv.size(); k++){ int tmp = (DP2[j][k] - (k?DP2[j][k-1]:0) + MOD) % MOD; DP[tv[k]] += tmp; DP[tv[k]] %= MOD; } } } for(int i=1; i<=n; i++) ans = (ans + DP[i]) % MOD; printf("%lld", ans); }

컴파일 시 표준 에러 (stderr) 메시지

boat.cpp: In function 'int main()':
boat.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d", &a[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...