Submission #4778445
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, Q; string S;
char T[201010], D[201010];
//---------------------------------------------------------------------------------------------------
int check(int x) {
rep(i, 0, Q) {
if (T[i] == S[x]) {
if (D[i] == 'L') x--;
else x++;
}
if (x < 0 or N <= x) return x;
}
return x;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> Q >> S;
rep(q, 0, Q) cin >> T[q] >> D[q];
int ans = N;
if (check(0) < 0) {
int ok = 0, ng = N;
while (ok + 1 != ng) {
int md = (ok + ng) / 2;
if (check(md) < 0) ok = md;
else ng = md;
}
ans -= ok + 1;
}
if (N <= check(N - 1)) {
int ng = -1, ok = N - 1;
while (ng + 1 != ok) {
int md = (ok + ng) / 2;
if (N <= check(md)) ok = md;
else ng = md;
}
ans -= N - ok;
}
cout << ans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Snuke the Wizard |
| User | hamayanhamayan |
| Language | C++14 (GCC 5.4.1) |
| Score | 500 |
| Code Size | 2161 Byte |
| Status | AC |
| Exec Time | 39 ms |
| Memory | 976 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 1 ms | 256 KiB |
| sample_02.txt | AC | 1 ms | 256 KiB |
| sample_03.txt | AC | 1 ms | 256 KiB |
| test_01.txt | AC | 20 ms | 916 KiB |
| test_02.txt | AC | 20 ms | 916 KiB |
| test_03.txt | AC | 21 ms | 916 KiB |
| test_04.txt | AC | 14 ms | 976 KiB |
| test_05.txt | AC | 15 ms | 976 KiB |
| test_06.txt | AC | 14 ms | 916 KiB |
| test_07.txt | AC | 16 ms | 976 KiB |
| test_08.txt | AC | 16 ms | 976 KiB |
| test_09.txt | AC | 23 ms | 848 KiB |
| test_10.txt | AC | 23 ms | 848 KiB |
| test_11.txt | AC | 19 ms | 848 KiB |
| test_12.txt | AC | 19 ms | 976 KiB |
| test_13.txt | AC | 23 ms | 976 KiB |
| test_14.txt | AC | 23 ms | 976 KiB |
| test_15.txt | AC | 26 ms | 976 KiB |
| test_16.txt | AC | 23 ms | 976 KiB |
| test_17.txt | AC | 18 ms | 916 KiB |
| test_18.txt | AC | 14 ms | 848 KiB |
| test_19.txt | AC | 39 ms | 916 KiB |
| test_20.txt | AC | 29 ms | 640 KiB |
| test_21.txt | AC | 37 ms | 916 KiB |
| test_22.txt | AC | 29 ms | 848 KiB |
| test_23.txt | AC | 19 ms | 916 KiB |
| test_24.txt | AC | 18 ms | 848 KiB |
| test_25.txt | AC | 17 ms | 848 KiB |
| test_26.txt | AC | 9 ms | 720 KiB |