Submission #4414976


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 104 D / Link: http://abc104.contest.atcoder.jp/tasks/abc104_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


template <::std::uint_fast32_t MODULO> class modint {
public:
	using uint32 = ::std::uint_fast32_t; using uint64 = ::std::uint_fast64_t; using value_type = uint32; uint32 a; modint() noexcept : a(0) {}modint(const uint32 x) noexcept : a(x) {}modint operator+(const modint &o) const noexcept { return a + o.a < MODULO ? modint(a + o.a) : modint(a + o.a - MODULO); }modint operator-(const modint &o) const noexcept { return modint(a < o.a ? a + MODULO - o.a : a - o.a); }modint operator*(const modint &o) const noexcept { return modint(static_cast<uint64>(a) * o.a % MODULO); }modint operator/(const modint &o) const { return modint(static_cast<uint64>(a) * (~o).a % MODULO); }modint &operator+=(const modint &o) noexcept { return *this = *this + o; }modint &operator-=(const modint &o) noexcept { return *this = *this - o; }modint &operator*=(const modint &o) noexcept { return *this = *this * o; }modint &operator/=(const modint &o) { return *this = *this / o; }modint operator~() const noexcept { return pow(MODULO - 2); }modint operator-() const noexcept { return a ? modint(MODULO - a) : *this; }modint operator++() noexcept { return a == MODULO - 1 ? a = 0 : ++a, *this; }modint operator--() noexcept { return a ? --a : a = MODULO - 1, *this; }bool operator==(const modint &o) const noexcept { return a == o.a; }bool operator!=(const modint &o) const noexcept { return a != o.a; }bool operator<(const modint &o) const noexcept { return a < o.a; }bool operator<=(const modint &o) const noexcept { return a <= o.a; }bool operator>(const modint &o) const noexcept { return a > o.a; }bool operator>=(const modint &o) const noexcept { return a >= o.a; }explicit operator bool() const noexcept { return a; }explicit operator uint32() const noexcept { return a; }modint pow(uint32 x) const noexcept { uint64 t = a, u = 1; while (x) { if (x & 1)u = u * t % MODULO; t = (t * t) % MODULO; x >>= 1; }	return modint(u); }
	uint32 get() const noexcept { return a; }
};
using mint = modint<MOD>;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string s; cin >> s;
	int N = SZ(s);
	vector<mint>dp(4, 0);
	dp[0] = 1;
	FOR(i, 0, N) {
		vector<mint>nx(4, 0);
		FOR(k, 0, 4) { // not step
			if (s[i] == '?') {
				nx[k] = dp[k] * 3;
				// !! 常に最短でやる必要はない 
			}
			else {
				nx[k] = dp[k];
			}
		}
		// step
		if (s[i] == 'A' || s[i] == '?') {
			nx[1] += dp[0];
		}
		if (s[i] == 'B' || s[i] == '?') {
			nx[2] += dp[1];
		}
		if (s[i] == 'C' || s[i] == '?') {
			nx[3] += dp[2];
		}
		nx.swap(dp);
	}


	mint ans = dp[3];
	cout << ans.get() << "\n";

	return 0;
}

Submission Info

Submission Time
Task D - We Love ABC
User Yang33
Language C++14 (GCC 5.4.1)
Score 400
Code Size 3837 Byte
Status AC
Exec Time 6 ms
Memory 512 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KiB
a02 AC 1 ms 256 KiB
a03 AC 1 ms 256 KiB
b04 AC 1 ms 256 KiB
b05 AC 1 ms 256 KiB
b06 AC 1 ms 256 KiB
b07 AC 1 ms 256 KiB
b08 AC 1 ms 256 KiB
b09 AC 1 ms 256 KiB
b10 AC 5 ms 512 KiB
b11 AC 6 ms 512 KiB
b12 AC 5 ms 512 KiB
b13 AC 5 ms 512 KiB
b14 AC 5 ms 512 KiB
b15 AC 5 ms 512 KiB
b16 AC 5 ms 512 KiB
b17 AC 6 ms 512 KiB
b18 AC 2 ms 256 KiB
b19 AC 1 ms 256 KiB
b20 AC 2 ms 256 KiB
b21 AC 6 ms 512 KiB
b22 AC 6 ms 512 KiB
b23 AC 6 ms 512 KiB