답안 #590763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590763 2022-07-06T10:42:23 Z Do_you_copy Toll (BOI17_toll) C++17
0 / 100
256 ms 359164 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 5e4 + 1;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int k, n, m, o;

ll dp[maxN][18][5][5];

void Init(){
    cin >> k >> n >> m >> o;
    memset(dp, 0x3f, sizeof(dp));
    int x = __lg(n) + 1;
    for (int i = 1; i <= m; ++i){
        int a, b, w;
        cin >> a >> b >> w;
        dp[a / k][0][a % k][b % k] = w;
    }
    for (int i = 1; i <= x; ++i){
        for (int j = 0; j < n / k; ++j){
            for (int p = 0; p < k; ++p){
                for (int q = 0; q < k; ++q){
                    for (int r = 0; r < k; ++r){
                        dp[j][i][p][r] = min(dp[j][i][p][r], dp[j][i - 1][p][q] + dp[j + (1 << (i - 1))][i - 1][q][r]);
                    }
                }
            }
        }
    }
    while (o--){
        int a, b;
        cin >> a >> b;
        int u = a % k, v = b % k, s = a / k, t = b / k - a / k;
        ll ans[5], tem[5];
        memset(ans, 0x3f, sizeof(ans));
        memset(tem, 0x3f, sizeof(ans));
        tem[u] = 0;
        while (t){
            int diff = t & -t;
            int lg = __lg(diff);
            for (int p = 0; p < 5; ++p){
                for (int q = 0; q < 5; ++q){
                    ans[p] = min(ans[p], tem[q] + dp[s][lg][q][p]);
                }
            }
            for (int p = 0; p < 5; ++p){
                tem[p] = ans[p];
                ans[p] = inf;
            }
            s = s + diff;
            t ^= diff;
        }
        cout << ((tem[v] - inf) ? tem[v] : -1) << "\n";
    }
}


int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 229 ms 358428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 256 ms 359164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 176456 KB Output is correct
2 Correct 69 ms 176328 KB Output is correct
3 Correct 63 ms 176356 KB Output is correct
4 Correct 66 ms 176332 KB Output is correct
5 Correct 70 ms 176324 KB Output is correct
6 Correct 64 ms 176384 KB Output is correct
7 Correct 65 ms 176364 KB Output is correct
8 Correct 66 ms 176424 KB Output is correct
9 Correct 67 ms 176484 KB Output is correct
10 Runtime error 235 ms 358356 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 176456 KB Output is correct
2 Correct 69 ms 176328 KB Output is correct
3 Correct 63 ms 176356 KB Output is correct
4 Correct 66 ms 176332 KB Output is correct
5 Correct 70 ms 176324 KB Output is correct
6 Correct 64 ms 176384 KB Output is correct
7 Correct 65 ms 176364 KB Output is correct
8 Correct 66 ms 176424 KB Output is correct
9 Correct 67 ms 176484 KB Output is correct
10 Runtime error 235 ms 358356 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 229 ms 358428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -