Submission #946526

#TimeUsernameProblemLanguageResultExecution timeMemory
946526n3rm1nBoat (APIO16_boat)C++17
31 / 100
1932 ms524288 KiB
/// boat #include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 505, MAXX = 1e6+10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, m; int a[MAXN], b[MAXN]; unordered_map < int, int > id; vector < int > g, u; void read_hash() { cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i] >> b[i]; for (int j = a[i]; j <= b[i]; ++ j) g.push_back(j); } sort(g.begin(), g.end()); u.push_back(g[0]); for (int i = 1; i < g.size(); ++ i) { if(u.back() != g[i]) u.push_back(g[i]); } for (int i = 0; i < u.size(); ++ i) { id[u[i]] = i+1; } } int dp[MAXX]; const int mod = 1e9 + 7; int pref[MAXX]; void solve() { int ans = 0; int maxx = u.size(); for (int i = 1; i <= n; ++ i) { for (int j = id[b[i]]; j >= id[a[i]]; -- j) { dp[j] += pref[j-1] + 1; dp[j] %= mod; } for (int j = id[a[i]]; j <= u.size(); ++ j) pref[j] = (pref[j-1] + dp[j]) % mod; } ans = pref[maxx]; ans %= mod; cout << ans << endl; } int main() { speed(); read_hash(); solve(); return 0; }

Compilation message (stderr)

boat.cpp: In function 'void read_hash()':
boat.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 1; i < g.size(); ++ i)
      |                     ~~^~~~~~~~~~
boat.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < u.size(); ++ i)
      |                     ~~^~~~~~~~~~
boat.cpp: In function 'void solve()':
boat.cpp:53:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j = id[a[i]]; j <= u.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...