結果
| 問題 |
No.3158 Collect Stamps
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-05-23 19:45:35 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,042 bytes |
| コンパイル時間 | 731 ms |
| コンパイル使用メモリ | 27,136 KB |
| 実行使用メモリ | 10,148 KB |
| 最終ジャッジ日時 | 2025-05-23 19:45:38 |
| 合計ジャッジ時間 | 2,706 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:22:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%lld %lld %lld", &n, &m, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:26:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%lld", &a[i]);
| ^~~~~~~~~~~~~~~~~~~~
main.c:31:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%lld", &t[i][j]);
| ^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
long long int min(long long int a, long long int b)
{
if (a < b)
return a;
else
return b;
}
long long int popcount(long long int n)
{
long long int res = 0;
for (; n > 0; n /= 2)
res += n % 2;
return res;
}
long long int a[8];
long long int t[16][16];
long long int dist[70004][16];
int main()
{
long long int n, m, k;
scanf("%lld %lld %lld", &n, &m, &k);
long long int i, j;
for (i = 0; i < k; i++)
{
scanf("%lld", &a[i]);
a[i]--;
}
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf("%lld", &t[i][j]);
for (i = 0; i < (1 << n); i++)
for (j = 0; j < n; j++)
dist[i][j] = 1e18;
for (i = 0; i < n; i++)
dist[1 << i][i] = 0;
long long int s;
for (s = 1; s < (1 << n); s++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
dist[s | (1 << j)][j] = min(dist[s | (1 << j)][j], dist[s][i] + t[i][j]);
long long int ans = 1e18;
for (i = 0; i < k; i++)
for (s = 0; s < (1 << n); s++)
if (popcount(s) >= m)
ans = min(ans, dist[s][a[i]]);
printf("%lld\n", ans);
return 0;
}
pengin_2000