Submission #617174

# Submission time Handle Problem Language Result Execution time Memory
617174 2022-08-01T09:20:38 Z AmirElarbi Monochrome Points (JOI20_monochrome) C++14
0 / 100
3 ms 340 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 4e5+5;
const int lg = 20;
int st[nax*4];
void update(int v, int l, int r, int pos, int val){
    if(pos > r || pos < l) return;
    if(l == r){
        st[v] += val;
        return;
    }
    int md = (l+r)/2;
    update(v*2, l, md, pos, val);
    update(v*2+1, md+1, r, pos, val);
    st[v] = st[v*2]+st[v*2+1];
}
int query(int v, int l, int r, int i, int j){
    if(i > r || j < l) return 0;
    if(i <= l && r <= j) return st[v];
    int md = (l+r)/2;
    return query(v*2, l, md, i, j)+ query(v*2+1, md+1, r, i, j);
}
int main() {
    optimise;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi blck, wht;
    for (int i = 0; i < n*2; ++i)
    {
        if(s[i] == 'B') blck.pb(i);
        if(s[i] == 'W') wht.pb(i);
    }
    int mx = 0;
    for (int i = 0; i < n; ++i)
    {
        int res = 0;
        memset(st, 0, sizeof st);
        vii qr;
        for (int j = 0; j < n; ++j)
        {
            int ind = (j+i)%n;
            int a = blck[j], b = wht[ind];
            if(a > b) swap(a,b);
            qr.pb({a,b});
        }
        sort(qr.begin(), qr.end());
        reverse(qr.begin(), qr.end());
        for(auto x : qr){
            res += query(1,0,2*n-1, x.fi, x.se);
            update(1,0,2*n-1, x.fi, 1);
            update(1,0,2*n-1, x.se, -1);
        }
        mx = max(res, mx);
    }
    cout << mx << endl;
}


Compilation message

monochrome.cpp: In function 'int main()':
monochrome.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
monochrome.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -