結果

問題 No.462 6日知らずのコンピュータ
ユーザー くれちー
提出日時 2016-12-24 13:40:34
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 25,600 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-14 17:21:12
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 WA * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%lld %lld", &n, &k);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:27:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                         scanf("%lld", &a);
      |                         ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define MOD 1000000007
#define int long long

signed getbit(int x, int n) {
	return !!(x & (signed)pow(2, n - 1));
}

int f(int x) {
	if (x > 1) return (x * f(x - 1)) % MOD;
	else return 1;
}

signed main() {
	int n, k;
	scanf("%lld %lld", &n, &k);

	int a, abit[61][60], cntb, cnt01, cnt10, flg = 0;
	int maxb = -1, minb = n + 1;
	int ans, i, j;

	if (k == 0) ans = f(n);
	else {
		rep(i, k) {
			scanf("%lld", &a);
			cntb = cnt01 = cnt10 = 0;
			rep(j, n) {
				abit[i][j] = getbit(a, j + 1);
				if (abit[i][j]) cntb++;
			}
			if (cntb > maxb) maxb = cntb;
			if (cntb < minb) minb = cntb;
			if (i > 0) {
				rep(j, n) {
					int t1 = abit[i][j], t2 = abit[i - 1][j];
					if (!t1 && t2) cnt01++;
					else if (t1 && !t2) cnt10++;
				}
				if (cnt01 && cnt10) {
					ans = 0;
					goto ans;
				}
				else if (flg && cnt01 && flg != 1) {
					ans = 0;
					goto ans;
				}
				else if (flg && cnt10 && flg != 2) {
					ans = 0;
					goto ans;
				}
				if (!flg && cnt01) flg = 1;
				else if (!flg && cnt10) flg = 2;
			}
		}
		ans = (f(minb) * f(maxb - minb) * f(n - maxb)) % MOD;
	}

	ans: printf("%lld\n", ans);
	return 0;
}
0