This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) (int(x.size()))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
struct przedzialowiec{
int N;
vector<int> t;
przedzialowiec(int n){
for(N = 1; N <= n;) N <<= 1;
t.resize(N<<1, 0);
}
void dodaj(int poz){
for(poz+=N; poz; poz>>=1) ++t[poz];
}
int suma(int p, int k){
int ret = 0;
for(p+=N, k+=N+1; p<k; p>>=1, k>>=1){
if(p&1) ret += t[p++];
if(k&1) ret += t[--k];
}
return ret;
}
};
int main(){
int n;
scanf("%d\n", &n);
int n2 = n<<1;
vector<int> s(n2);
REP(i, n2){
char c;
scanf("%c", &c);
s[i] = c=='B';
}
int wyn = 0;
REP(xd, n){
vector<pii> prz;
vector<vector<int>> lewo(2), prawo(2);
REP(i, n) lewo[s[i]].emplace_back(i);
FOR(i, n, n2-1) prawo[s[i]].emplace_back(i);
REP(i, ssize(lewo[0])) prz.emplace_back(lewo[0][i], prawo[1][i]);
REP(i, ssize(lewo[1])) prz.emplace_back(lewo[1][i], prawo[0][i]);
int tmp = 0;
sort(all(prz));
przedzialowiec przed(n);
REP(i, n){
pii t = prz[i];
tmp += przed.suma(0, t.se-n);
przed.dodaj(t.se-n);
}
wyn = max(wyn, tmp);
s.insert(s.begin(), s.back());
s.pop_back();
}
printf("%d", wyn);
return 0;
}
Compilation message (stderr)
monochrome.cpp: In function 'int main()':
monochrome.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d\n", &n);
| ~~~~~^~~~~~~~~~~~
monochrome.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |