Submission #37025190
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double PI = acos(-1);
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
string ns;
char now = 'Z';
vector<int> idx_asy(n);
rep(i,n) {
if (s[i] != now) {
ns += s[i];
}
idx_asy[i] = ns.size()-1;
now = s[i];
}
n = ns.size();
vector<int> l(q), r(q);
rep(i,q) {
cin >> l[i] >> r[i];
l[i]--; r[i]--;
l[i] = idx_asy[l[i]];
r[i] = idx_asy[r[i]];
// cout << l[i] << " " << r[i] << endl;
}
vector<int> ans(q, INF);
rep(i,q) {
int num = r[i] - l[i] + 1;
if (num == 1) ans[i] = 0;
else if (ns[l[i]] == ns[r[i]]) {
ans[i] = (num-2)/2 + 1;
} else {
ans[i] = (num-1)/2 + 1;
}
}
rep(i,q) cout << ans[i] << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - My Last ABC Problem |
| User | taki0711 |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1292 Byte |
| Status | AC |
| Exec Time | 188 ms |
| Memory | 5144 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 01.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 6 ms | 3612 KiB |
| 02.txt | AC | 170 ms | 4556 KiB |
| 03.txt | AC | 167 ms | 4124 KiB |
| 04.txt | AC | 170 ms | 4176 KiB |
| 05.txt | AC | 188 ms | 5052 KiB |
| 06.txt | AC | 185 ms | 5084 KiB |
| 07.txt | AC | 187 ms | 4920 KiB |
| 08.txt | AC | 183 ms | 4972 KiB |
| 09.txt | AC | 184 ms | 5144 KiB |