提出 #373722


ソースコード 拡げる

// L.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long LL;

int s_to_i[256];
int v[20];

LL calc(const char *exp) {
	LL len = strlen(exp);
	LL tot = 0;
	LL prev = v[0];
	for (LL i = 2; i < len; i += 2) {
		if (exp[i - 1] == '+') {
			tot += prev;
			prev = v[s_to_i[exp[i]]];
		} else {
			prev *= v[s_to_i[exp[i]]];
		}
	}
	return tot + prev;
}

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	memset(s_to_i, -1, sizeof(s_to_i));
	s_to_i['+'] = s_to_i['*'] = 0;
	LL cnt = 0;
	for (LL i = 0; i < s.length(); ++i) {
		char c = s[i];
		if (s_to_i[c] < 0) {
			s_to_i[c] = cnt++;
		}
	}
	LL ans = 0;
	if (cnt <= 20) {
		LL m = 1LL << 30;
		LL b = 1LL << cnt;
		for (LL i = 0; i < b; ++i) {
			for (LL j = 0; j < cnt; ++j) {
				v[j] = ((1LL << j) & i) ? 1 : -1;
			}
			LL a = calc(s.c_str());
			if (a < m) {
				m = a;
				ans = 0;
			}
			ans += a == m;
		}
	}
	cout << ans << endl;
	return 0;
}

提出情報

提出日時
問題 L - セミ時雨ハッシュ
ユーザ greentea
言語 C++ (GCC 4.9.2)
得点 30
コード長 1064 Byte
結果 WA
実行時間 236 ms
メモリ 928 KiB

ジャッジ結果

セット名 Subtask All
得点 / 配点 30 / 30 0 / 270
結果
AC × 12
AC × 24
WA × 26
セット名 テストケース
Subtask subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, scrambled_27.txt, scrambled_28.txt, scrambled_29.txt, scrambled_30.txt, scrambled_31.txt, scrambled_32.txt, scrambled_33.txt, scrambled_34.txt, scrambled_35.txt, scrambled_36.txt, scrambled_37.txt, subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt
ケース名 結果 実行時間 メモリ
scrambled_00.txt AC 25 ms 792 KiB
scrambled_01.txt AC 24 ms 792 KiB
scrambled_02.txt WA 24 ms 924 KiB
scrambled_03.txt WA 25 ms 920 KiB
scrambled_04.txt WA 24 ms 920 KiB
scrambled_05.txt WA 25 ms 788 KiB
scrambled_06.txt WA 25 ms 916 KiB
scrambled_07.txt WA 25 ms 844 KiB
scrambled_08.txt WA 25 ms 920 KiB
scrambled_09.txt WA 25 ms 924 KiB
scrambled_10.txt WA 24 ms 916 KiB
scrambled_11.txt WA 23 ms 804 KiB
scrambled_12.txt WA 25 ms 792 KiB
scrambled_13.txt WA 24 ms 916 KiB
scrambled_14.txt WA 25 ms 916 KiB
scrambled_15.txt WA 25 ms 924 KiB
scrambled_16.txt WA 26 ms 812 KiB
scrambled_17.txt WA 25 ms 732 KiB
scrambled_18.txt WA 25 ms 928 KiB
scrambled_19.txt WA 23 ms 844 KiB
scrambled_20.txt WA 25 ms 804 KiB
scrambled_21.txt WA 22 ms 924 KiB
scrambled_22.txt AC 24 ms 920 KiB
scrambled_23.txt AC 23 ms 920 KiB
scrambled_24.txt AC 25 ms 924 KiB
scrambled_25.txt AC 29 ms 752 KiB
scrambled_26.txt AC 29 ms 804 KiB
scrambled_27.txt AC 34 ms 800 KiB
scrambled_28.txt AC 47 ms 928 KiB
scrambled_29.txt AC 72 ms 924 KiB
scrambled_30.txt AC 124 ms 928 KiB
scrambled_31.txt AC 236 ms 928 KiB
scrambled_32.txt WA 25 ms 924 KiB
scrambled_33.txt WA 24 ms 928 KiB
scrambled_34.txt WA 23 ms 924 KiB
scrambled_35.txt WA 24 ms 924 KiB
scrambled_36.txt WA 25 ms 924 KiB
scrambled_37.txt WA 25 ms 804 KiB
subtask_00.txt AC 25 ms 800 KiB
subtask_01.txt AC 23 ms 928 KiB
subtask_02.txt AC 24 ms 800 KiB
subtask_03.txt AC 27 ms 768 KiB
subtask_04.txt AC 25 ms 924 KiB
subtask_05.txt AC 27 ms 840 KiB
subtask_06.txt AC 30 ms 800 KiB
subtask_07.txt AC 36 ms 808 KiB
subtask_08.txt AC 47 ms 916 KiB
subtask_09.txt AC 72 ms 804 KiB
subtask_10.txt AC 125 ms 804 KiB
subtask_11.txt AC 235 ms 808 KiB