답안 #233087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233087 2020-05-19T10:21:27 Z triple_fault 3단 점프 (JOI19_jumps) C++14
0 / 100
4000 ms 1784 KB
/* fucking change this 2020 */

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <random>

#define ll long long

using namespace std;

//rng
/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll L, ll R) {
    return uniform_int_distribution<ll>(L, R)(rng);
}*/

void foo() {
    ll n; scanf("%lld", &n);
    ll vals[n];
    for (ll i = 0; i < n; ++i) scanf("%lld", &vals[i]);

    ll q; scanf("%lld", &q);
    while (q --) {
        ll a, b; scanf("%lld %lld", &a, &b);
        --a; --b;

        ll mxv = -1, idx = -1;
        vector<ll> eq;
        for (ll i = a; i <= b; ++i) {
            if (vals[i] > mxv) {
                mxv = vals[i];
                idx = i;
                eq.clear();
                eq.push_back(i);
            } else if (vals[i] == mxv) eq.push_back(i);
        }

        ll ans = 0;
        for (auto &each: eq) {
            idx = each;
        for (ll i = a; i < idx; ++i) {
            ll dif = idx - i;
            for (ll j = idx + dif; j <= b; ++j) 
                ans = max(ans, vals[i] + vals[j]);
        }
    
        for (ll i = a; i < idx; ++i) {
            ll dif = idx - i;
            for (ll j = max(i - dif, a); j < i; ++j) ans = max(ans, vals[i] + vals[j]);
        }
        for (ll i = idx + 1; i <= b; ++i) {
            ll dif = i - idx;
            for (ll j = i + dif; j <= b; ++j) ans = max(ans, vals[i] + vals[j]);
        }
        }

        printf("%lld\n", ans + vals[idx]);
    }
}

int main(void) {
    ll t = 1;
    while (t --) foo();
    return 0;
}

Compilation message

jumps.cpp: In function 'void foo()':
jumps.cpp:25:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ll n; scanf("%lld", &n);
           ~~~~~^~~~~~~~~~~~
jumps.cpp:27:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (ll i = 0; i < n; ++i) scanf("%lld", &vals[i]);
                                ~~~~~^~~~~~~~~~~~~~~~~~
jumps.cpp:29:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ll q; scanf("%lld", &q);
           ~~~~~^~~~~~~~~~~~
jumps.cpp:31:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ll a, b; scanf("%lld %lld", &a, &b);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4059 ms 1784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -