結果
| 問題 |
No.1313 N言っちゃダメゲーム (4)
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2020-12-10 00:39:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,010 bytes |
| コンパイル時間 | 1,650 ms |
| コンパイル使用メモリ | 169,040 KB |
| 実行使用メモリ | 5,504 KB |
| 最終ジャッジ日時 | 2024-09-19 07:07:28 |
| 合計ジャッジ時間 | 2,710 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
int N;
vector<T> BIT;
binary_indexed_tree(int n){
N = 1;
while (N < n){
N *= 2;
}
BIT = vector<T>(N + 1, 0);
}
void add(int i, T x){
i++;
while (i <= N){
BIT[i] += x;
i += i & -i;
}
}
T sum(int i){
T ans = 0;
while (i > 0){
ans += BIT[i];
i -= i & -i;
}
return ans;
}
T sum(int L, int R){
return sum(R) - sum(L);
}
};
int main(){
int N, K;
cin >> N >> K;
string S;
cin >> S;
vector<int> dp(N + 1, 0);
binary_indexed_tree<int> BIT(N + 1);
for (int i = N - 1; i >= 0; i--){
bool ok = true;
if (i != 0){
if (S[i - 1] == 'x'){
ok = false;
}
}
if (ok){
if (BIT.sum(i + 1, min(i + K, N) + 1) == 0){
dp[i] = 1;
BIT.add(i, 1);
}
}
}
if (dp[0] == 1){
cout << 0 << endl;
} else {
for (int i = 1; i <= K; i++){
if (dp[i] == 1){
cout << i << endl;
}
}
}
}
SSRS