# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
25546 |
2017-06-23T04:06:37 Z |
윤교준(#1076) |
스트랩 (JOI14_straps) |
C++11 |
|
33 ms |
21672 KB |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MOD (1000000007)
#define MAXN (2005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
int d[MAXN][MAXN];
bool chk[MAXN][MAXN];
int A[MAXN], B[MAXN], P[MAXN];
int N, Ans;
int main() {
for(int i = 0; i < MAXN; i++) fill(d[i], d[i]+MAXN, -INF);
scanf("%d", &N);
for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]);
for(int i = 1; i <= N; i++) A[i]--;
for(int i = 1; i <= N; i++) P[i] = i;
sort(P+1, P+N+1, [&](const int& a, const int& b) -> bool { return A[a] > A[b]; });
d[0][1] = 0; chk[0][1] = true;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
if(!chk[i-1][j]) continue;
upmax(d[i][min(N, j+A[P[i]])], d[i-1][j] + B[P[i]]);
chk[i][min(N, j+A[P[i]])] = true;
}
for(int j = 0; j <= N; j++) {
if(!chk[i-1][j]) continue;
chk[i][j] = true; upmax(d[i][j], d[i-1][j]);
}
}
for(int i = 0; i <= N; i++) upmax(Ans, d[N][i]);
printf("%d\n", Ans);
return 0;
}
Compilation message
straps.cpp: In function 'int main()':
straps.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
straps.cpp:47:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21672 KB |
Output is correct |
2 |
Correct |
3 ms |
21672 KB |
Output is correct |
3 |
Correct |
3 ms |
21672 KB |
Output is correct |
4 |
Correct |
0 ms |
21672 KB |
Output is correct |
5 |
Correct |
0 ms |
21672 KB |
Output is correct |
6 |
Correct |
9 ms |
21672 KB |
Output is correct |
7 |
Correct |
0 ms |
21672 KB |
Output is correct |
8 |
Correct |
0 ms |
21672 KB |
Output is correct |
9 |
Correct |
0 ms |
21672 KB |
Output is correct |
10 |
Correct |
9 ms |
21672 KB |
Output is correct |
11 |
Correct |
0 ms |
21672 KB |
Output is correct |
12 |
Correct |
6 ms |
21672 KB |
Output is correct |
13 |
Correct |
0 ms |
21672 KB |
Output is correct |
14 |
Correct |
0 ms |
21672 KB |
Output is correct |
15 |
Correct |
6 ms |
21672 KB |
Output is correct |
16 |
Correct |
0 ms |
21672 KB |
Output is correct |
17 |
Correct |
6 ms |
21672 KB |
Output is correct |
18 |
Correct |
3 ms |
21672 KB |
Output is correct |
19 |
Correct |
3 ms |
21672 KB |
Output is correct |
20 |
Correct |
0 ms |
21672 KB |
Output is correct |
21 |
Correct |
0 ms |
21672 KB |
Output is correct |
22 |
Correct |
0 ms |
21672 KB |
Output is correct |
23 |
Correct |
3 ms |
21672 KB |
Output is correct |
24 |
Correct |
0 ms |
21672 KB |
Output is correct |
25 |
Correct |
6 ms |
21672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21672 KB |
Output is correct |
2 |
Correct |
3 ms |
21672 KB |
Output is correct |
3 |
Correct |
0 ms |
21672 KB |
Output is correct |
4 |
Correct |
3 ms |
21672 KB |
Output is correct |
5 |
Correct |
6 ms |
21672 KB |
Output is correct |
6 |
Correct |
3 ms |
21672 KB |
Output is correct |
7 |
Correct |
0 ms |
21672 KB |
Output is correct |
8 |
Correct |
6 ms |
21672 KB |
Output is correct |
9 |
Correct |
13 ms |
21672 KB |
Output is correct |
10 |
Correct |
6 ms |
21672 KB |
Output is correct |
11 |
Correct |
6 ms |
21672 KB |
Output is correct |
12 |
Correct |
23 ms |
21672 KB |
Output is correct |
13 |
Correct |
9 ms |
21672 KB |
Output is correct |
14 |
Correct |
6 ms |
21672 KB |
Output is correct |
15 |
Correct |
16 ms |
21672 KB |
Output is correct |
16 |
Correct |
13 ms |
21672 KB |
Output is correct |
17 |
Correct |
9 ms |
21672 KB |
Output is correct |
18 |
Correct |
19 ms |
21672 KB |
Output is correct |
19 |
Correct |
19 ms |
21672 KB |
Output is correct |
20 |
Correct |
19 ms |
21672 KB |
Output is correct |
21 |
Correct |
23 ms |
21672 KB |
Output is correct |
22 |
Correct |
13 ms |
21672 KB |
Output is correct |
23 |
Correct |
29 ms |
21672 KB |
Output is correct |
24 |
Correct |
19 ms |
21672 KB |
Output is correct |
25 |
Correct |
33 ms |
21672 KB |
Output is correct |
26 |
Correct |
33 ms |
21672 KB |
Output is correct |
27 |
Correct |
23 ms |
21672 KB |
Output is correct |
28 |
Correct |
23 ms |
21672 KB |
Output is correct |
29 |
Correct |
26 ms |
21672 KB |
Output is correct |
30 |
Correct |
19 ms |
21672 KB |
Output is correct |
31 |
Correct |
19 ms |
21672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21672 KB |
Output is correct |
2 |
Correct |
6 ms |
21672 KB |
Output is correct |
3 |
Correct |
3 ms |
21672 KB |
Output is correct |
4 |
Correct |
3 ms |
21672 KB |
Output is correct |
5 |
Correct |
6 ms |
21672 KB |
Output is correct |
6 |
Correct |
0 ms |
21672 KB |
Output is correct |
7 |
Correct |
6 ms |
21672 KB |
Output is correct |
8 |
Correct |
0 ms |
21672 KB |
Output is correct |
9 |
Correct |
6 ms |
21672 KB |
Output is correct |
10 |
Correct |
9 ms |
21672 KB |
Output is correct |
11 |
Correct |
13 ms |
21672 KB |
Output is correct |
12 |
Correct |
9 ms |
21672 KB |
Output is correct |
13 |
Correct |
6 ms |
21672 KB |
Output is correct |
14 |
Correct |
6 ms |
21672 KB |
Output is correct |
15 |
Correct |
6 ms |
21672 KB |
Output is correct |
16 |
Correct |
3 ms |
21672 KB |
Output is correct |
17 |
Correct |
19 ms |
21672 KB |
Output is correct |
18 |
Correct |
6 ms |
21672 KB |
Output is correct |
19 |
Correct |
9 ms |
21672 KB |
Output is correct |
20 |
Correct |
13 ms |
21672 KB |
Output is correct |
21 |
Correct |
13 ms |
21672 KB |
Output is correct |
22 |
Correct |
13 ms |
21672 KB |
Output is correct |
23 |
Correct |
6 ms |
21672 KB |
Output is correct |
24 |
Correct |
13 ms |
21672 KB |
Output is correct |
25 |
Correct |
13 ms |
21672 KB |
Output is correct |
26 |
Correct |
13 ms |
21672 KB |
Output is correct |
27 |
Correct |
6 ms |
21672 KB |
Output is correct |
28 |
Correct |
19 ms |
21672 KB |
Output is correct |
29 |
Correct |
13 ms |
21672 KB |
Output is correct |
30 |
Correct |
9 ms |
21672 KB |
Output is correct |
31 |
Correct |
13 ms |
21672 KB |
Output is correct |
32 |
Correct |
16 ms |
21672 KB |
Output is correct |
33 |
Correct |
13 ms |
21672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
21672 KB |
Output is correct |
2 |
Correct |
13 ms |
21672 KB |
Output is correct |
3 |
Correct |
16 ms |
21672 KB |
Output is correct |
4 |
Correct |
16 ms |
21672 KB |
Output is correct |
5 |
Correct |
19 ms |
21672 KB |
Output is correct |
6 |
Correct |
16 ms |
21672 KB |
Output is correct |
7 |
Correct |
19 ms |
21672 KB |
Output is correct |
8 |
Correct |
33 ms |
21672 KB |
Output is correct |
9 |
Correct |
19 ms |
21672 KB |
Output is correct |
10 |
Correct |
16 ms |
21672 KB |
Output is correct |
11 |
Correct |
23 ms |
21672 KB |
Output is correct |
12 |
Correct |
26 ms |
21672 KB |
Output is correct |
13 |
Correct |
16 ms |
21672 KB |
Output is correct |
14 |
Correct |
23 ms |
21672 KB |
Output is correct |
15 |
Correct |
29 ms |
21672 KB |
Output is correct |
16 |
Correct |
23 ms |
21672 KB |
Output is correct |
17 |
Correct |
29 ms |
21672 KB |
Output is correct |
18 |
Correct |
19 ms |
21672 KB |
Output is correct |
19 |
Correct |
16 ms |
21672 KB |
Output is correct |
20 |
Correct |
19 ms |
21672 KB |
Output is correct |
21 |
Correct |
23 ms |
21672 KB |
Output is correct |
22 |
Correct |
23 ms |
21672 KB |
Output is correct |
23 |
Correct |
13 ms |
21672 KB |
Output is correct |
24 |
Correct |
13 ms |
21672 KB |
Output is correct |
25 |
Correct |
16 ms |
21672 KB |
Output is correct |