제출 #1167575

#제출 시각아이디문제언어결과실행 시간메모리
1167575nguynCollecting Stamps 3 (JOI20_ho_t3)C++20
100 / 100
88 ms132168 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 205;
const ll inf = 1e18;

int n, l; 
int x[N], t[N]; 
ll f[N][N][N][2]; 

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n >> l; 
    for (int i = 1; i <= n; i++) {
        cin >> x[i]; 
    }
    for (int i = 1; i <= n; i++) {
        cin >> t[i]; 
    }
    x[0] = 0;
    x[n + 1] = l; 
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            for (int k = 0; k <= n; k++) {
                for (int t = 0; t < 2; t++) {
                    f[i][j][k][t] = inf;
                }
            }
        }
    } 
    f[0][n + 1][0][0] = f[0][n + 1][0][1] = 0; 
    for (int i = 0; i < n; i++) {
        for (int j = n + 1; j > i + 1; j--) {
            for (int k = 0; k < n; k++) {
                ll tmp = min(f[i][j][k][0] + x[i + 1] - x[i], f[i][j][k][1] + l - (x[j] - x[i + 1]));
                if (tmp <= t[i + 1]) f[i + 1][j][k + 1][0] = min(f[i + 1][j][k + 1][0], tmp);
                else f[i + 1][j][k][0] = min(f[i + 1][j][k][0], tmp);
                tmp = min(f[i][j][k][0] + l - (x[j - 1] - x[i]), f[i][j][k][1] + x[j] - x[j - 1]);
                if (tmp <= t[j - 1]) f[i][j - 1][k + 1][1] = min(f[i][j - 1][k + 1][1], tmp);
                else f[i][j - 1][k][1] = min(f[i][j - 1][k][1], tmp);
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            for (int k = 0; k <= n; k++) {
                for (int t = 0; t < 2; t++) {
                    if (f[i][j][k][t] != inf) {
                        res = max(res, k); 
                    }   
                }
            }
        }
    } 
    cout << res;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...