結果

問題 No.1313 N言っちゃダメゲーム (4)
ユーザー morimariomorimario
提出日時 2020-12-10 01:16:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 3,932 bytes
コンパイル時間 2,606 ms
コンパイル使用メモリ 216,912 KB
実行使用メモリ 13,848 KB
最終ジャッジ日時 2023-10-19 11:33:07
合計ジャッジ時間 4,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 62 ms
13,848 KB
testcase_14 AC 62 ms
13,848 KB
testcase_15 AC 120 ms
13,848 KB
testcase_16 AC 94 ms
9,096 KB
testcase_17 AC 16 ms
4,348 KB
testcase_18 AC 66 ms
8,900 KB
testcase_19 AC 56 ms
7,424 KB
testcase_20 AC 8 ms
4,484 KB
testcase_21 AC 23 ms
4,348 KB
testcase_22 AC 29 ms
6,328 KB
testcase_23 AC 38 ms
6,880 KB
testcase_24 AC 6 ms
4,384 KB
testcase_25 AC 53 ms
9,164 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 16 ms
4,348 KB
testcase_28 AC 55 ms
5,400 KB
testcase_29 AC 57 ms
5,664 KB
testcase_30 AC 77 ms
9,360 KB
testcase_31 AC 58 ms
5,928 KB
testcase_32 AC 77 ms
10,152 KB
testcase_33 AC 12 ms
5,400 KB
testcase_34 AC 8 ms
4,608 KB
testcase_35 AC 53 ms
12,528 KB
testcase_36 AC 19 ms
6,984 KB
testcase_37 AC 22 ms
7,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using pdd = pair<double, double>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using pbb = pair<bool, bool>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using pss = pair<string, string>; using vs = vector<string>; using vvs = vector<vs>; using vvvs = vector<vvs>;
#define rep2(counter, start, goal) for (int counter = (int)(start); counter < (int)(goal); ++counter)
#define rep(counter, goal) rep2(counter, 0, goal)
#define rep3(counter, start, goal) for (int counter = (int)(start); counter > (int)(goal); --counter)
#define rep0(times) for (int counter = 0; counter < (int)(times); ++counter)
#define all(container) begin(container), end(container)
template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; }
template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; }
void yn(bool flag) { cout << (flag ? "yes" : "no") << "\n"; }
void Yn(bool flag) { cout << (flag ? "Yes" : "No") << "\n"; }
void YN(bool flag) { cout << (flag ? "YES" : "NO") << "\n"; }
void set_prec(const int &digits) { cout << fixed << setprecision(digits); cerr << fixed << setprecision(digits); }
template <typename T> void pr(const T &obj) { cerr << obj; }
template <typename T, typename ...Ts> void pr(const T &first, const Ts &...rest) { pr(first); pr(", "); pr(rest...); }
template <typename S, typename T> void pr(const pair<S, T> &pair) { pr("("); pr(pair.first); pr(", "); pr(pair.second); pr(")"); }
template <typename T> void pr(const vector<T> &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); }
template <typename T> void pr(const vector<vector<T>> &vv) { pr("\n"); rep(index, vv.size()) { pr("["); pr(index); pr("]: "); pr(vv[index]); pr("\n"); } }
template <typename T> void pr(const set<T> &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); }
template <typename S, typename T> void pr(const map<S, T> &map) { pr("{"); for (pair<S, T> pair : map) { pr("("); pr(pair.first); pr(": "); pr(pair.second); pr("), "); } pr("}"); }
#define db(obj) cerr << #obj << ": "; pr(obj); cerr << " "
#define dl(obj) db(obj); cerr << "\n";
#define dm(...) cerr << "(" << #__VA_ARGS__ << "): ("; pr(__VA_ARGS__); cerr << ") "
#define dml(...) dm(__VA_ARGS__); cerr << "\n"
// #include <atcoder/all>
// using namespace atcoder;
// const ll MOD = 1000000007; // 998244353;
// const ll INF = 1000000007;

// i:N-1~1 として Grundy数 g[i] を順次定めていく
// (S[i]=='x' のとき g[i] = -1 とする)
// g[i] は T(i) = {g[i+j]|j:1~K-1} の mex
// 今見ているiに対し、j:1~K での g[i+j]=G となる jの個数m[G](G:0~K) と T(i)のmexを管理
// i+K+1 が N未満かつ危険でない場合、--m[g[i+K+1]], mex処理、
// iが危険でない場合、 g[i] <- mex, mex処理
// を繰り返す

int main() {
	// 0-ind
	int N, K; cin >> N >> K;
	string S; cin >> S; // 1~N-1
	S = "o" + S; // 0~N-1
	// dl(S);

	vi g(N, -1); // 0~N-1
	map<int, int> m; // m[G]: j:1~Kでg[i+j]=Gとなるjの個数
	set<int> s; // m[G]=0 であるようなGの集合 *begin(s) がmexとなる
	rep(i, K + 1) s.insert(i);

	// db(g); dl(m); dl(s);
	
	rep3(i, N - 1, 0) { // i: N-1 ~ 1
		// db(i); db(S[i]); dl(S[i - 1]);
		if (S[i] == 'o') {
			g[i] = *begin(s);
			s.erase(g[i]);
			++m[g[i]];
		}
		if (i + K <= N && S[i + K] == 'o') {
			--m[g[i + K]];
			if (m[g[i + K]] == 0) s.insert(g[i + K]);
		}

		// db(g); db(m); dl(s);
	}
	bool f = false;
	rep2(i, 1, K + 1) if (g[i] == 0) {
		cout << i << endl;
		f = true;
	}
	if (!f) cout << 0 << endl;
}
0