Submission #47258

#TimeUsernameProblemLanguageResultExecution timeMemory
47258ngkan146Boat (APIO16_boat)C++11
9 / 100
66 ms4844 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = (ll) 1e9+7; int n, a[505], b[505]; ll f[505][3005]; ll g[505]; int main(){ iostream::sync_with_stdio(0); cin >> n; vector <int> lst; for(int i=1;i<=n;i++) cin >> a[i] >> b[i], lst.push_back(a[i]), lst.push_back(b[i]); sort(lst.begin(), lst.end()); lst.resize(unique(lst.begin(),lst.end()) - lst.begin()); vector <pair<int,int> > range; for(int i=0;i<lst.size();i++){ range.push_back({lst[i], lst[i]}); if (i != lst.size() - 1 && lst[i]+1 <= lst[i+1]-1) range.push_back({lst[i]+1, lst[i+1]-1}); } range.insert(range.begin(), {-1,-1}); g[0] = 1; ll ans = 0; for(int j = 1;j < range.size();j ++){ // f[i][j] = cnt of way that end at i and value of i in range j int len = range[j].second - range[j].first + 1; ll arr[505], sumG[505]; arr[0] = 1; sumG[0] = g[0]; for(int i=1;i<=n;i++) sumG[i] = (sumG[i-1] + g[i]) % mod, arr[i] = arr[i-1] * (len+1-i) % mod; for(int i=1;i<=n;i++){ if (range[j].first < a[i] || b[i] < range[j].second) continue; int possiBoat = 0; ll tmp = 0; for(int ii=i;ii>=1;ii--){ if (!(a[ii] <= range[j].first && range[j].second <= b[ii])) continue; possiBoat += (a[ii] <= range[j].first && range[j].second <= b[ii]); tmp = (tmp + arr[possiBoat]) % mod; if (possiBoat > len) break; f[i][j] = (f[i][j] + sumG[ii-1 ] * tmp % mod) % mod; } ans = (ans + f[i][j]) % mod; } for(int i=0;i<=n;i++){ g[i] = (g[i] + f[i][j]) % mod; } } cout << ans; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<lst.size();i++){
                 ~^~~~~~~~~~~
boat.cpp:22:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i != lst.size() - 1 && lst[i]+1 <= lst[i+1]-1)
             ~~^~~~~~~~~~~~~~~~~
boat.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 1;j < range.size();j ++){
                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...