Submission #441345

# Submission time Handle Problem Language Result Execution time Memory
441345 2021-07-05T03:15:37 Z cpp219 Toll (BOI17_toll) C++14
7 / 100
175 ms 84804 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e4 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
vector<ll> g[N];
ll k,n,m,Q,x,y,w,dp[N][17][5][5],tmp[5][5],ans[5][5];

void Reset(ll a[5][5]){
    for (ll i = 0;i < k;i++)
        for (ll j = 0;j < k;j++) a[i][j] = inf;
}

void Copy(){
     for (ll i = 0;i < k;i++)
        for (ll j = 0;j < k;j++) ans[i][j] = tmp[i][j];
}

void combine(ll tar[5][5],ll a[5][5],ll b[5][5]){
    for (ll i = 0;i < k;i++)
        for (ll j = 0;j < k;j++)
            for (ll l = 0;l < k;l++){
                tar[i][j] = min(tar[i][j],a[i][l] + b[l][j]);
            }
}

void out(ll a[5][5]){
    for (ll i = 0;i < 5;i++){
        for (ll j = 0;j < 5;j++) cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    exit(0);
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>k>>n>>m>>Q;
    for (ll i = 0;i < n;i++)
        for (ll j = 0;j < 17;j++) Reset(dp[i][j]);
    while(m--){
        cin>>x>>y>>w;
        dp[x/k][0][x%k][y%k] = w;
    }
    for (ll j = 1;j < 17;j++){
        for (ll i = 0;i <= n;i++){
            if (i + (1 << (j - 1)) > n) continue;
            combine(dp[i][j],dp[i][j - 1],dp[i + (1 << (j - 1))][j - 1]);

        }
    }
    //out(dp[0][0]);
    while(Q--){
        cin>>x>>y;
        ll cur = x/k,tar = y/k; memset(ans,0,sizeof(ans));
        for (ll i = 16;i >= 0;i--){
            if (cur + (1 << i) > tar) continue;
            //out(dp[cur][i]);
            Reset(tmp); combine(tmp,ans,dp[cur][i]); Copy();

            cur += (1 << i);
        }
        if (ans[x % k][y % k] != inf && x/k < y/k) cout<<ans[x % k][y % k];
        else cout<<-1; cout<<"\n";
    }
}

Compilation message

toll.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
toll.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
toll.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
toll.cpp: In function 'int main()':
toll.cpp:77:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   77 |         else cout<<-1; cout<<"\n";
      |         ^~~~
toll.cpp:77:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   77 |         else cout<<-1; cout<<"\n";
      |                        ^~~~
toll.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 84804 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 3 ms 3148 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 104 ms 84644 KB Output is correct
9 Correct 104 ms 84668 KB Output is correct
10 Correct 83 ms 84684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 175 ms 84676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Incorrect 1 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Incorrect 1 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 84804 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 3 ms 3148 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 104 ms 84644 KB Output is correct
9 Correct 104 ms 84668 KB Output is correct
10 Correct 83 ms 84684 KB Output is correct
11 Incorrect 175 ms 84676 KB Output isn't correct
12 Halted 0 ms 0 KB -