Submission #946716

#TimeUsernameProblemLanguageResultExecution timeMemory
946716Ice_manBoat (APIO16_boat)C++14
9 / 100
2079 ms435860 KiB
#include <iostream> #include <chrono> #include <set> #include <vector> #include <map> #include <cstring> #define maxn 505 #define maxlog 20 #define mod 1000000007 #define INF 1000000010 #define LINF 1000000000000000005 #define endl '\n' #define pb(x) push_back(x) #define X first #define Y second #define control cout<<"passed"<<endl; #pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math") #pragma GCC target("avx2") using namespace std; std::chrono::high_resolution_clock::time_point startT, currT; constexpr double TIME_MULT = 1; double timePassed() { using namespace std::chrono; currT = high_resolution_clock::now(); double time = duration_cast<duration<double>>(currT - startT).count(); return time * TIME_MULT; } int l[maxn], r[maxn]; int n; int dp[maxn]; void read() { cin >> n; for(int i = 0; i < n; i++) cin >> l[i] >> r[i]; } int ans = 0; void calc_dp() { set <int> s; for(int i = 0; i < n; i++) for(int j = l[i]; j <= r[i]; j++) s.insert(j); vector <int> v; for(int e : s) v.pb(e); /**for(int e : v) cout << e << " "; cout << endl;*/ map <int , int> mem; for(int i = 0; i < v.size(); i++) mem[v[i]] = i + 1; for(int i = 0; i < n; i++) { l[i] = mem[l[i]]; r[i] = mem[r[i]]; } /**for(int i = 0; i < n; i++) cout << l[i] << " - " << r[i] << endl;*/ for(int i = 0; i <= v.size(); i++) dp[i] = 0; dp[0] = 1; long long pom = 0 , prev; for(int i = 0; i < n; i++) { pom = 0LL; for(int j = 0; j <= r[i]; j++) { prev = dp[j]; if(j >= l[i]) { dp[j] += pom; dp[j] %= mod; } pom += prev; pom %= mod; } } long long ans = 0; for(int i = 1; i <= v.size(); i++) { ans += dp[i]; ans %= mod; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //startT = std::chrono::high_resolution_clock::now(); read(); calc_dp(); return 0; }

Compilation message (stderr)

boat.cpp: In function 'void calc_dp()':
boat.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0; i < v.size(); i++)
      |                    ~~^~~~~~~~~~
boat.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0; i <= v.size(); i++)
      |                    ~~^~~~~~~~~~~
boat.cpp:111:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for(int i = 1; i <= v.size(); 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...