Submission #157322

# Submission time Handle Problem Language Result Execution time Memory
157322 2019-10-10T16:24:42 Z karma 스트랩 (JOI14_straps) C++14
50 / 100
52 ms 16172 KB
#include<bits/stdc++.h>
#define FileName      "test"
#define ll            long long
#define pb            emplace_back
#define deg           first
#define c             second

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e3) + 2;
const int oo = int(2e9) + 7;

int f[N][N], Max[N], PMax[N], a[N];
int n, m, res = 0, pre;
pii val[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen(FileName".inp", "r")) {
       freopen(FileName".inp", "r", stdin);
       freopen(FileName".out", "w", stdout);
    }
    cin >> n; m = n + 1;
    for(int i = 1; i <= n; ++i) {
        cin >> val[i].deg >> val[i].c;
        fill(f[i], f[i] + m + 1, -oo);
    }
    sort(val + 1, val + n + 1, [](const pii& x, const pii& y) {
             return x.deg > y.deg;
         });
    fill(Max, Max + m + 1, -oo);
    fill(PMax, PMax + m + 1, -oo);
    f[0][1] = 0; PMax[1] = Max[1] = 0;
    for(int i = 1; i <= n; ++i) {
       for(int j = 0; j < m; ++j) {
          pre = min(j + 1 - val[i].deg, m - 1);
          if(pre <= 0 || Max[pre] == -oo) continue;
          res = max(res, (f[i][j] = Max[pre] + val[i].c));
       }
       pre = m + 1 - val[i].deg;
       if(pre > 0 && PMax[pre] != -oo) res = max(res, (f[i][m] = PMax[pre] + val[i].c));
       for(int j = 0; j <= m; ++j) Max[j] = max(Max[j], f[i][j]);
       for(int j = m; j >= 0; --j) PMax[j] = max(PMax[j + 1], Max[j]);
    }
    cout << res;
}
///4375336

Compilation message

straps.cpp: In function 'int main()':
straps.cpp:23:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
        freopen(FileName".inp", "r", stdin);
        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
straps.cpp:24:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
        freopen(FileName".out", "w", stdout);
        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 15 ms 476 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 428 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 848 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 15 ms 8184 KB Output is correct
9 Correct 14 ms 8188 KB Output is correct
10 Correct 17 ms 8184 KB Output is correct
11 Correct 15 ms 8184 KB Output is correct
12 Correct 39 ms 16120 KB Output is correct
13 Correct 39 ms 15992 KB Output is correct
14 Correct 40 ms 16148 KB Output is correct
15 Correct 40 ms 16120 KB Output is correct
16 Correct 39 ms 16120 KB Output is correct
17 Correct 40 ms 16120 KB Output is correct
18 Correct 40 ms 16120 KB Output is correct
19 Correct 40 ms 16152 KB Output is correct
20 Correct 40 ms 15992 KB Output is correct
21 Incorrect 40 ms 16120 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 14 ms 8184 KB Output is correct
10 Correct 16 ms 8184 KB Output is correct
11 Correct 15 ms 8212 KB Output is correct
12 Correct 17 ms 8184 KB Output is correct
13 Correct 14 ms 8184 KB Output is correct
14 Correct 14 ms 8184 KB Output is correct
15 Correct 14 ms 8184 KB Output is correct
16 Correct 17 ms 8184 KB Output is correct
17 Correct 40 ms 16120 KB Output is correct
18 Correct 47 ms 15992 KB Output is correct
19 Correct 39 ms 16120 KB Output is correct
20 Correct 39 ms 16108 KB Output is correct
21 Correct 39 ms 15992 KB Output is correct
22 Correct 39 ms 16120 KB Output is correct
23 Correct 39 ms 16120 KB Output is correct
24 Correct 39 ms 15996 KB Output is correct
25 Correct 39 ms 16020 KB Output is correct
26 Correct 39 ms 16120 KB Output is correct
27 Correct 40 ms 16124 KB Output is correct
28 Correct 40 ms 16120 KB Output is correct
29 Correct 45 ms 16120 KB Output is correct
30 Correct 45 ms 16120 KB Output is correct
31 Correct 46 ms 16124 KB Output is correct
32 Correct 44 ms 16120 KB Output is correct
33 Correct 44 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 16112 KB Output is correct
2 Correct 52 ms 16120 KB Output is correct
3 Correct 44 ms 16172 KB Output is correct
4 Correct 45 ms 16120 KB Output is correct
5 Correct 42 ms 16120 KB Output is correct
6 Correct 44 ms 16124 KB Output is correct
7 Correct 41 ms 16120 KB Output is correct
8 Correct 40 ms 15992 KB Output is correct
9 Incorrect 45 ms 15992 KB Output isn't correct
10 Halted 0 ms 0 KB -