提出 #63416685
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
const int N=90,S=1<<9;
typedef long long ll;
#define mkp make_pair
int n,k;
ll f[N][N][S];
bool vis[N];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >q;
ll dis[N][N];
void dij(int st,int s)
{
for(int i=1;i<=n;i++) vis[i]=0;
for(int i=1;i<=n;i++) q.push(mkp(f[st][i][S],i));
while(!q.empty())
{
auto t=q.top(); q.pop();
int u=t.second;
if(vis[u]) continue;
vis[u]=1;
for(int j=1;j<=n;j++)
{
int v=j; ll w=dis[u][v];
if(f[st][v][s]>f[st][u][s]+w)
{
f[st][v][s]=f[st][u][s]+w;
if(!vis[v]) q.push(mkp(f[st][v][s],v));
}
}
}
}
int Q;
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) scanf("%lld",&dis[i][j]);
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
memset(f,0x3f,sizeof(f));
for(int u=1;u<=n;u++)
{
f[u][u][1<<k]=0;
for(int i=1;i<=k;i++) f[u][i][(1<<(i-1))]=0;
for(int s=1;s<(1<<(k+1));s++)
{
for(int msk=s;msk;msk=(msk-1)&s)
for(int i=1;i<=n;i++)
f[u][i][s]=min(f[u][i][s],f[u][i][msk]+f[u][i][msk^s]);
dij(u,s);
}
}
scanf("%d",&Q); int u,v;
int full=(1<<(k+1))-1;
while(Q--)
{
scanf("%d%d",&u,&v);
ll ans=0x3f3f3f3f3f3f3f3f;
for(int i=1;i<=n;i++) ans=min(ans,f[u][i][full]+dis[i][v]);
printf("%lld\n",ans);
}
}
提出情報
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:40:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | for(int j=1;j<=n;j++) scanf("%lld",&dis[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:59:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | scanf("%d",&Q); int u,v;
| ~~~~~^~~~~~~~~
Main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%d%d",&u,&v);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp: In function ‘void dij(int, int)’:
Main.cpp:17:48: warning: array subscript 512 is above array bounds of ‘ll [512]’ {aka ‘long long int [512]’} [-Warray-bounds]
17 | for(int i=1;i<=n;i++) q.push(mkp(f[st][i][S],i));
| ~~~~~~~~~~^
Main.cpp:9:4: note: while referencing ‘f’
9 | ll f[N][N][S];
| ^
ジャッジ結果
| セット名 |
Sample |
All |
AfterContest |
| 得点 / 配点 |
0 / 0 |
625 / 625 |
0 / 0 |
| 結果 |
|
|
|
| セット名 |
テストケース |
| Sample |
00-sample-001.txt, 00-sample-002.txt |
| All |
00-sample-001.txt, 00-sample-002.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 02-small-001.txt, 02-small-002.txt, 02-small-003.txt, 02-small-004.txt, 02-small-005.txt, 02-small-006.txt, 02-small-007.txt, 02-small-008.txt, 02-small-009.txt, 02-small-010.txt, 03-large-001.txt, 03-large-002.txt, 03-large-003.txt, 03-large-004.txt, 03-large-005.txt, 03-large-006.txt, 03-large-007.txt, 03-large-008.txt, 03-large-009.txt, 03-large-010.txt, 03-large-011.txt, 03-large-012.txt, 03-large-013.txt, 03-large-014.txt, 03-large-015.txt |
| AfterContest |
99-after_contest-001.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00-sample-001.txt |
AC |
14 ms |
36100 KiB |
| 00-sample-002.txt |
AC |
14 ms |
36220 KiB |
| 01-random-001.txt |
AC |
19 ms |
36228 KiB |
| 01-random-002.txt |
AC |
15 ms |
36164 KiB |
| 01-random-003.txt |
AC |
168 ms |
36124 KiB |
| 01-random-004.txt |
AC |
326 ms |
36168 KiB |
| 01-random-005.txt |
AC |
270 ms |
36096 KiB |
| 01-random-006.txt |
AC |
475 ms |
36168 KiB |
| 01-random-007.txt |
AC |
15 ms |
36224 KiB |
| 01-random-008.txt |
AC |
53 ms |
36116 KiB |
| 01-random-009.txt |
AC |
88 ms |
36232 KiB |
| 01-random-010.txt |
AC |
23 ms |
36308 KiB |
| 02-small-001.txt |
AC |
15 ms |
36260 KiB |
| 02-small-002.txt |
AC |
15 ms |
36220 KiB |
| 02-small-003.txt |
AC |
15 ms |
36276 KiB |
| 02-small-004.txt |
AC |
15 ms |
36172 KiB |
| 02-small-005.txt |
AC |
15 ms |
36336 KiB |
| 02-small-006.txt |
AC |
15 ms |
36104 KiB |
| 02-small-007.txt |
AC |
15 ms |
36204 KiB |
| 02-small-008.txt |
AC |
15 ms |
36280 KiB |
| 02-small-009.txt |
AC |
15 ms |
36336 KiB |
| 02-small-010.txt |
AC |
15 ms |
36100 KiB |
| 03-large-001.txt |
AC |
389 ms |
36268 KiB |
| 03-large-002.txt |
AC |
388 ms |
36272 KiB |
| 03-large-003.txt |
AC |
956 ms |
36144 KiB |
| 03-large-004.txt |
AC |
392 ms |
36308 KiB |
| 03-large-005.txt |
AC |
900 ms |
36276 KiB |
| 03-large-006.txt |
AC |
961 ms |
36372 KiB |
| 03-large-007.txt |
AC |
858 ms |
36160 KiB |
| 03-large-008.txt |
AC |
362 ms |
36332 KiB |
| 03-large-009.txt |
AC |
418 ms |
36276 KiB |
| 03-large-010.txt |
AC |
375 ms |
36336 KiB |
| 03-large-011.txt |
AC |
377 ms |
36140 KiB |
| 03-large-012.txt |
AC |
388 ms |
36384 KiB |
| 03-large-013.txt |
AC |
394 ms |
36144 KiB |
| 03-large-014.txt |
AC |
368 ms |
36272 KiB |
| 03-large-015.txt |
AC |
934 ms |
36344 KiB |
| 99-after_contest-001.txt |
AC |
796 ms |
36336 KiB |