Submission #157324

# Submission time Handle Problem Language Result Execution time Memory
157324 2019-10-10T16:33:02 Z karma 스트랩 (JOI14_straps) C++14
0 / 100
73 ms 31736 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 * 2], Max[N * 2], PMax[N * 2], 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 = 2 * n + 2;
    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);
          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;
}
///4.15 - 483686693

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 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 31736 KB Output isn't correct
2 Halted 0 ms 0 KB -