# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1261500 | phtung | Election (BOI18_election) | C++20 | 3 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "IO"
#define int long long
const int inf = 1e18 + 7;
const int maxn = 5e5 + 5;
int n, q;
string s;
void solve()
{
cin >> n >> s;
s = ' ' + s;
cin >> q;
while(q--)
{
int l, r;
cin >> l >> r;
int cntc = 0, cntt = 0, res = 0;
for(int i = l; i <= r; i++)
{
cntc += (s[i] == 'C');
cntt += (s[i] == 'T');
if(cntt > cntc)
{
res++;
cntt--;
}
}
int dem = 0;
cntc = cntt = 0;
for(int i = r; i >= l; i--)
{
cntc += (s[i] == 'C');
cntt += (s[i] == 'T');
if(cntt > cntc)
{
dem++;
cntt--;
}
}
res = max(res, dem);
cout << res << "\n";
}
}
signed main()
{
if (fopen (name".INP", "r"))
{
freopen (name".INP", "r", stdin);
freopen (name".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
int t = 1;
while(t--) solve();
std::cerr << "Time: " << clock() - start << "ms\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |