# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
825527 | boyliguanhan | Election (BOI18_election) | C++17 | 681 ms | 179968 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct Data {
int l=0,r=0,s=0,a=0;
Data():l(0){}
Data(bool b) : l(b), r(b), s(b?1:-1), a(b){}
Data(Data a, Data b) : l(max(a.l, a.s+b.l)), r(max(b.r,b.s+a.r)), s(a.s+b.s), a(max(max(a.a+b.s, b.a+a.s), a.l+b.r)){}
};
vector<vector<Data>> tb(500100, vector<Data>(20));
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
string str;
cin >> n >> str >> q;
for(int i = 1; i <= n; i++) {
tb[i][0] = Data(str[i-1]=='T');
}
for(int j = 1; j < 20; j++)
for(int i = 1; i < n-(1<<j)+2; i++)
tb[i][j] = Data(tb[i][j-1], tb[i+(1<<j-1)][j-1]);
while(q--){
Data d;
int a, b;
cin >> a >> b;
for(int i = 20;i--;)
if(a+(1<<i)-2<b)
d = Data(d,tb[a][i]), a+=(1<<i);
cout << d.a << '\n';
}
컴파일 시 표준 에러 (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... |