Submission #5445944
Source Code Expand
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; static const string words[] = {"tokyo", "kyoto"}; int main() { int T; cin >> T; for (int i{}; i < T; ++i) { vector<P> vec; string S; cin >> S; for (const auto& word : words) { for (size_t pos{}; (pos = S.find(word, pos)) != string::npos; ++pos) { // pos += hoge.length() wouldn't allow overlapping occurrences to be found. vec.push_back(P{pos, pos + word.length()}); } } sort(vec.begin(), vec.end(), [](P l, P r) { if (l.second == r.second) return l.first > r.first; return l.second < r.second; }); int ans{}; int pos{}; for (const auto& p : vec) { if (pos <= p.first) { ++ans; pos = p.second; } } cout << ans << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - 東京都 |
User | tatsu |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 880 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 256 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 10_random_to_kyo.txt, 20_noised_tokyoto.txt, 99_teuchi.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
10_random_to_kyo.txt | AC | 2 ms | 256 KB |
20_noised_tokyoto.txt | AC | 2 ms | 256 KB |
99_teuchi.txt | AC | 2 ms | 256 KB |