제출 #1215601

#제출 시각아이디문제언어결과실행 시간메모리
1215601sasdeToll (BOI17_toll)C++20
0 / 100
147 ms196168 KiB
#include<bits/stdc++.h>
using namespace std;
bool M1;
#define task "aws"
#define sz(a) (int)a.size()
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define inf 1e18
#define emf emplace_front
#define em emplace
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time   cerr << "TIME : " << clock() * 0.001 << "s" <<'\n'
const int N=5e4+5,lg=15,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
// #define int long long
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,1,-1,1,-1};
int node,o,k,edges;
struct pt
{
    long long x[5][5];
    pt(){
        for(int i=0;i<5;++i){
            for(int j=0;j<5;++j){
                x[i][j]=inf;
            }
        }
    }
};
pt dp[N][lg+5];
pt combine(pt x,pt y){
    pt res;
    for(int i=0;i<k;++i){
        for(int j=0;j<k;++j){
            for(int u=0;u<k;++u){
                res.x[i][j]=min(res.x[i][j],x.x[i][u]+y.x[u][j]);
            }
        }
    }
    // for(int i=0;i<k;++i){
    //     for(int j=0;j<k;++j)cout <<res.x[i][j]<<" ";cout<<'\n';
    // }
    return res;
}
void build(void){
    for(int j=1;j<=lg;++j)
    for(int i=0;i<=node/k;++i){
        dp[i][j]=combine(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
    }
}
long long get(int a,int b){
    int x=a%k;
    int y=b%k;
    pt res;
    for(int i=0;i<k;++i)res.x[i][i]=0;
    a/=k,b/=k;
    if(a>=b){
        return -1;;
    }
    int dist=(b-a);
    for(int j=0;j<=lg;++j){
        if(dist&(1<<j)){
            res=combine(res,dp[a][j]);
            a+=(1<<j);
        }
    }
    return res.x[x][y];
}
bool M2;
void solve(){
    cin >> k >> node >> edges >> o;
    for(int i=1;i<=edges;++i){
        int u,v;
        long long w;
        cin >> u >> v >> w;
        int x=u%k,y=v%k;
        dp[u/k][0].x[x][y]=min(dp[u/k][0].x[x][y],w);
        // cout <<x<<" "<<y<<'\n';
    }
    build();
    while(o--){
        int a,b;
        cin >> a >> b;
        long long u=get(a,b);
        cout <<(u==inf?-1:u)<<'\n';
    }
}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
}
look_memory;
look_time;
}

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

toll.cpp:103:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  103 | main()
      | ^~~~
toll.cpp: In function 'int main()':
toll.cpp:110:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:111:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...