제출 #162681

#제출 시각아이디문제언어결과실행 시간메모리
162681rama_pangShortcut (IOI16_shortcut)C++14
71 / 100
2062 ms2296 KiB
#include "shortcut.h"
#include <bits/stdc++.h>

#define NO_DEBUG
#ifndef NO_DEBUG
#define debug(x) cerr << #x << " is " << x << "\n"
#endif

using namespace std;
using lint = long long;

const lint INF = 1e18;

int N, C;
vector<lint> X;
vector<lint> D;

bool is_valid(lint T) {
    bool valid = false;
    lint max_sum = +INF; // maximum of S1 + S2 that is valid
    lint min_sum = -INF; // minimum of S1 + S2 that is valid
    lint max_dif = +INF; // maximum of S1 - S2 that is valid
    lint min_dif = -INF; // minimum of S1 - S2 that is valid

    for (int j = 0; j < N; j++) {
        for (int i = 0; i < j; i++) {
            if (X[j] - X[i] + D[j] + D[i] > T) {
                max_sum = min(max_sum, + T - (- X[i] - X[j] + D[i] + D[j] + C));
                min_sum = max(min_sum, - T + (+ X[i] + X[j] + D[i] + D[j] + C));
                max_dif = min(max_dif, + T - (- X[i] + X[j] + D[i] + D[j] + C));
                min_dif = max(min_dif, - T + (+ X[i] - X[j] + D[i] + D[j] + C));
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (min_sum <= X[i] + X[j] && X[i] + X[j] <= max_sum && 
                min_dif <= X[i] - X[j] && X[i] - X[j] <= max_dif) 
            {
                valid = true;
            }
        }
    }

    #ifndef NO_DEBUG
        cerr << "====================== ";
        debug(T);
        debug(max_sum);
        debug(min_sum);
        debug(max_dif);
        debug(min_dif);
        cerr << "\n\n";
    #endif

    return valid;
}

lint find_shortcut(int n_, vector<int> l_, vector<int> d_, int c_) {
    N = n_, C = c_;
    X.resize(N), D.resize(N);
    for (int i = 0; i < l_.size(); i++)
        X[i + 1] = X[i] + l_[i];
    for (int i = 0; i < d_.size(); i++)
        D[i] = d_[i];
    
    lint res = 0;
    for (lint L = 0, R = INF, M = (L + R) / 2; L <= R; M = (L + R) / 2) {
        if (is_valid(M))
            R = M - 1, res = M;
        else
            L = M + 1;
    }

    return res;
}

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

shortcut.cpp: In function 'lint find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:62:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < l_.size(); i++)
                     ~~^~~~~~~~~~~
shortcut.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < d_.size(); i++)
                     ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...