# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
111236 |
2019-05-14T11:43:13 Z |
tictaccat |
Boat (APIO16_boat) |
C++14 |
|
17 ms |
8448 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000 + 5;
const int MOD = 1e9 + 7;
const int INV2 = 5e8 + 4;
int N,ans;
vector<int> a(MAX), b(MAX), ways(2*MAX), newWays(2*MAX), bin; //ways[i] = ways of ending between bin[i] and bin[i+1]-1
vector<vector<int>> Z(MAX), val(MAX,vector<int>(MAX));
vector<int> invs(MAX,-1);
int exp(int a, int e) {
if (e == 0) return 1;
if (e%2 == 1) return a * exp(a,e-1) % MOD;
int temp = exp(a,e/2);
return temp * temp % MOD;
}
int inv(int k) {
if (invs[k] != -1) return invs[k];
int D = 1;
for (int i = 0; i < k; i++) {
D *= i+1;
D %= MOD;
}
return invs[k] = exp(D,MOD-2);
}
int choose(int n, int k) {
int N = 1;
for (int i = 0; i < k; i++) {
N *= (n-i);
N %= MOD;
}
return N * inv(k) % MOD;
}
int pre(int k) {
int res = 0;
int sz = bin[k+1] - bin[k];
// cout << sz << "\n";
val[k][0] = 1;
for (int i = 1; i <= N; i++) {
val[k][i] = val[k][i-1] * (sz+i-1) % MOD * inv(i) % MOD;
//cout << sz+i-1 << " " << i << ": " << val[k][i] << " " << choose(sz+i-1,i) << "\n";
// val[k][i] = choose(sz+i-1,i);
}
return res;
}
int calc(int k) {
int res = 0;
for (int i = 1; i <= Z[k].size(); i++) {
res += val[k][i] * Z[k][Z[k].size()-i] % MOD;
res %= MOD;
}
return res;
}
main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
b[i]++;
bin.push_back(a[i]);
bin.push_back(b[i]);
}
sort(bin.begin(),bin.end());
bin.erase(unique(bin.begin(),bin.end()),bin.end());
for (int i = 0; i < bin.size(); i++) pre(i);
for (int i = 0; i < N; i++) {
cout << i << "\n";
int pre = 1, k = 0;
for (; bin[k] < a[i]; k++) {pre += ways[k]; pre %= MOD;}
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
Z[k].push_back(pre);
newWays[k] = calc(k);
pre += ways[k];
pre %= MOD;
}
ways = newWays;
}
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
cout << (ans < 0 ? ans + MOD : ans) << "\n";
return 0;
}
Compilation message
boat.cpp: In function 'long long int calc(long long int)':
boat.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= Z[k].size(); i++) {
~~^~~~~~~~~~~~~~
boat.cpp: At global scope:
boat.cpp:64:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
boat.cpp: In function 'int main()':
boat.cpp:78:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < bin.size(); i++) pre(i);
~~^~~~~~~~~~~~
boat.cpp:84:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
~~~~^~~~~~~~~~~~
boat.cpp:93:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
8320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
8320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
8448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
8320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |