이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 505;
const int MOD = 1e9 + 7;
int mult(ll x, ll y) {return x * y % MOD;}
int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}
int sub(int x, int y) {x -= y;if(x < 0) x += MOD;return x;}
int n, m;
int a[maxn], b[maxn];
int dp[maxn * 3], pref[maxn * 3], sum[maxn * 3];
int main() {
scanf("%d", &n);
for(int i = 0;i < n;i++)
scanf("%d%d", a + i, b + i);
set<int> s;
s.insert(0);
for(int i = 0;i < n;i++)
s.insert(a[i]), s.insert(b[i]), s.insert(b[i] + 1);
vector<int> v(all(s));
m = v.size();
dp[0] = sum[0] = 1;
for(int i = 0;i < m;i++)
pref[i] = 1;
for(int i = 0;i < n;i++) {
int lo = 0, hi = 0;
for(int j = 0;j < m;j++) {
if(v[j] == a[i]) lo = j;
if(v[j] == b[i]) hi = j;
}
for(int j = hi;j >= lo;j--) {
sum[j] = add(sum[j], mult(pref[j - 1], v[j + 1] - v[j]));
dp[j] = add(dp[j], pref[j - 1]);
}
for(int j = 0;j < m;j++) {
pref[j] = sum[j];
if(j) pref[j] = add(pref[j], pref[j - 1]);
}
}
printf("%d\n", sub(pref[m - 1], 1));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
boat.cpp: In function 'int main()':
boat.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d", a + i, b + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |