답안 #584460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584460 2022-06-27T12:19:42 Z dxz05 Pinball (JOI14_pinball) C++14
51 / 100
1000 ms 4980 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

#include <random>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 1111;

long long pinball(int m, int n, vector<int> a, vector<int> b, vector<int> c, vector<int> d) {
    map<int, int> mp;
    mp[1] = mp[n] = 0;
    for (int i = 0; i < m; i++){
        mp[a[i]] = mp[b[i]] = mp[c[i]] = 0;
    }

    n = 0;
    for (auto &now : mp) now.second = ++n;

    for (int i = 0; i < m; i++){
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
        c[i] = mp[c[i]];
    }

    vector<ll> dp1(m, LLINF), dp2(m, LLINF);

    ll ans = LLINF;
    for (int i = 0; i < m; i++){
        if (a[i] == 1){
            dp1[i] = d[i];
        } else {
            for (int j = 0; j < i; j++) {
                if (a[i] <= c[j] && c[j] <= b[i]){
                    dp1[i] = min(dp1[i], dp1[j] + d[i]);
                }
            }
        }

        if (b[i] == n){
            dp2[i] = d[i];
        } else {
            for (int j = 0; j < i; j++) {
                if (a[i] <= c[j] && c[j] <= b[i]){
                    dp2[i] = min(dp2[i], dp2[j] + d[i]);
                }
            }
        }

        debug(dp1[i], dp2[i]);
        ans = min(ans, dp1[i] + dp2[i] - d[i]);
    }

    if (ans > 1e16) ans = -1;

    return ans;
}

void solve(int TC) {
    int m, n;
    cin >> m >> n;

    vector<int> a(m), b(m), c(m), d(m);
    for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    cout << pinball(m, n, a, b, c, d) << endl;

}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
    //    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        //debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

#ifdef dddxxz
    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

pinball.cpp: In function 'long long int pinball(int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
pinball.cpp:21:20: warning: statement has no effect [-Wunused-value]
   21 | #define debug(...) 42
      |                    ^~
pinball.cpp:87:9: note: in expansion of macro 'debug'
   87 |         debug(dp1[i], dp2[i]);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 6 ms 464 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 6 ms 468 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 5 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 6 ms 464 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 6 ms 468 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 5 ms 548 KB Output is correct
25 Correct 383 ms 1884 KB Output is correct
26 Execution timed out 1079 ms 4980 KB Time limit exceeded
27 Halted 0 ms 0 KB -