제출 #1162885

#제출 시각아이디문제언어결과실행 시간메모리
1162885son2008Toll (BOI17_toll)C++20
0 / 100
264 ms199048 KiB
#include<bits/stdc++.h>
using namespace std;
#define task "task"
#define ii pair<int,int>
#define fi first
#define se second
#define int long long
#define ll long long
#define ld double
#define mp make_pair
#define lg2 30
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define base 29
#define eps 1e-8
int dx[]= {0LL,0LL,1,-1,1,1,-1,-1};
int dy[]= {1,-1,0LL,0LL,1,-1,1,-1};
const int maxn=1e5+5;
const int mod=1e9+7;
int k,m,n,o,a[maxn],dp[1005][1005][5][5];
//dp[u/k][v/k][u%k][v%k]=dp[u/k][c/k][u%k][c%k]+dp[c/k][v/k][c%k][v%k];
void init()
{
    cin>>k>>n>>m    >>o;
    for(int u=0;u<=(n+k-1)/k;u++)
    {
        for(int v=0;v<=(n+k-1)/k;v++)
        {
            for(int i=0;i<k;i++)
            {
                for(int j=0;j<k;j++)
                {
                    dp[u][v][i][j]=1e18;
                }
            }
        }
    }
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        dp[u/k][v/k][u%k][v%k]=w;
    }
}
void process()
{
    for(int c=0;c<=(n+k-1)/k;c++)
    {
        for(int u=0;u<=(n+k-1)/k;u++)
        {
            for(int v=c;v<=(n+k-1)/k;v++)
            {
                for(int ku=0;ku<k;ku++)
                {
                    for(int kv=0;kv<k;kv++)
                    {
                        for(int kc=0;kc<k;kc++)
                        {
                            dp[u][v][ku][kv]=min(dp[u][v][ku][kv],dp[u][c][ku][kc]+dp[c][v][kc][kv]);
                        }
                    }
                }
            }
        }
    }
    cout<<dp[0][2][0%k][12%k]<<'\n';
    while(o--)
    {
        int a,b;
        cin>>a>>b;
        if(dp[a/k][b/k][a%k][b%k]==1e18)
            cout<<-1<<'\n';
        else
        cout<<dp[a/k][b/k][a%k][b%k]<<'\n';
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    init();
    process();
    cerr <<endl<< "TIME : " << clock() * 0.001 << "s" << endl ;
}

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

toll.cpp: In function 'int main()':
toll.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         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...