結果

問題 No.2178 Payable Magic Items
ユーザー square1001square1001
提出日時 2023-01-06 21:40:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 73,888 KB
実行使用メモリ 17,076 KB
最終ジャッジ日時 2023-08-21 08:11:50
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 70 ms
9,428 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 69 ms
9,544 KB
testcase_06 AC 69 ms
9,696 KB
testcase_07 WA -
testcase_08 AC 70 ms
9,452 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 125 ms
16,440 KB
testcase_12 AC 124 ms
16,780 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	// step #1. input
	int N, K;
	cin >> N >> K;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	// step #2. compute ID number
	vector<int> pow6(K + 1);
	pow6[0] = 1;
	for (int i = 1; i <= K; i++) {
		pow6[i] = pow6[i - 1] * 6;
	}
	vector<int> id(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < K; j++) {
			id[i] += (int(S[i][j] - '0') + 1) * pow6[j];
		}
	}

	// step #3. cumulative sum
	vector<int> sum(pow6[K]);
	for (int i = 0; i < N; i++) {
		sum[id[i]] += 1;
	}
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < pow6[K]; j++) {
			if ((j / pow6[i]) % 6 != 0) {
				sum[j - pow6[i]] += sum[j];
			}
		}
	}

	// step #4. calculate answer
	int answer = 0;
	for (int i = 0; i < N; i++) {
		if (sum[id[i]] >= 2) {
			answer += 1;
		}
	}

	// step #5. output
	cout << answer << endl;

	return 0;
}
0