結果
| 問題 |
No.3091 The Little Match Boy
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-03-09 13:24:13 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 906 bytes |
| コンパイル時間 | 1,563 ms |
| コンパイル使用メモリ | 26,112 KB |
| 実行使用メモリ | 43,008 KB |
| 最終ジャッジ日時 | 2025-03-09 13:24:21 |
| 合計ジャッジ時間 | 6,786 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 62 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:19:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d %d", &N, &M);
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:20:34: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | for (i = 1; i <= M; i++) scanf("%d", &(S[i]));
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
typedef struct HList {
struct HList *next;
int i, j;
} hlist;
#define HASH 5000011
const int H_Mod = HASH;
int hash_func(int i, int j)
{
return (((long long)i << 30) + j) % H_Mod;
}
int main()
{
int i, N, M, S[100001];
scanf("%d %d", &N, &M);
for (i = 1; i <= M; i++) scanf("%d", &(S[i]));
int hn = 0, h, ii, jj, p[100001];
hlist *hash[HASH] = {}, hd[100001], *hp;
for (i = 1; i <= N; i++) p[i] = i;
for (i = 1; i <= M; i++) {
p[S[i]] ^= p[S[i]+1];
p[S[i]+1] ^= p[S[i]];
p[S[i]] ^= p[S[i]+1];
ii = p[S[i]];
jj = p[S[i]+1];
if (ii > jj) {
ii ^= jj;
jj ^= ii;
ii ^= jj;
}
h = hash_func(ii, jj);
for (hp = hash[h]; hp != NULL; hp = hp->next) if (hp->i == ii && hp->j == jj) break;
if (hp == NULL) {
hd[hn].i = ii;
hd[hn].j = jj;
hd[hn].next = hash[h];
hash[h] = &(hd[hn++]);
}
}
printf("%d\n", hn);
fflush(stdout);
return 0;
}