Submission #292893

# Submission time Handle Problem Language Result Execution time Memory
292893 2020-09-07T14:38:58 Z limabeans Monochrome Points (JOI20_monochrome) C++17
25 / 100
2000 ms 928 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n;
string s;
bool used[maxn];

template<typename T> struct bit1 {
    T add(T x, T y) {
	return x+y;
    }
    int n;
    vector<T> t;
    void init(int n) {
	this->n=n;
	t.resize(n+10);
    }
    T qry(int i) {
	T res=0;
	for (; i>0; i-=i&-i) res=add(res,t[i]);
	return res;
    }
    void upd(int i, T dx) {
	assert(i>=1 && i<=n);
	for (; i<=n; i+=i&-i) t[i]=add(t[i],dx);
    }
};


bool isect(pair<int,int> p, pair<int,int> q) {
    if (max(p.first,q.first) >= min(p.second,q.second)) return false;
    if (p.first>q.first) swap(p,q);
    if (p.first<=q.first && q.second<=p.second) return false;
    return true;
}

ll eval_brute(vector<pair<int,int>> v) {
    assert(int(v.size())==n/2);
    for (auto &p: v) {
	if (p.first>p.second) {
	    swap(p.first,p.second);
	}
    }
    ll res = 0;
    
    for (int i=0; i<n/2; i++) {
	for (int j=i+1; j<n/2; j++) {
	    if (isect(v[i],v[j])) res++;
	}
    }

    return res;

    
}


ll eval(vector<pair<int,int>> v) {
    assert(int(v.size())==n/2);
    int N = 0;
    vector<pair<int,int>> ev;
    map<int,int> close, open;
    for (auto &p: v) {
	if (p.first>p.second) {
	    swap(p.first,p.second);
	}
	p.first++;
	p.second++;
	N = max(N, p.second);
	ev.push_back({p.first,0});
	ev.push_back({p.second,1});
	close[p.first]=p.second;
	open[p.second]=p.first;
    }
			
    ll res = 0;
    bit1<ll> bit;
    bit.init(N);

    sort(ev.begin(), ev.end());
    
    for (auto p: ev) {
	if (p.second==0) {
	    bit.upd(p.first,+1);
	}
	if (p.second==1) {
	    bit.upd(open[p.first],-1);
	    int l = open[p.first];
	    int r = p.first;
	    assert(l<=r);
	    res += (bit.qry(r)-bit.qry(l-1));
	}
    }

    return res;
}

ll brute() {
    ll best=0;
    vector<int> B, W;
    for (int i=0; i<n; i++) {
	if (s[i]=='B') B.push_back(i); else W.push_back(i);
    }

    for (int iter=0; iter<n/2; iter++) {
	vector<pair<int,int>> v;
	for (int i=0; i<n/2; i++) {
	    v.push_back({B[i],W[i]});
	}
	ll res = eval(v);
	//cout<<iter<<": "<<eval_brute(v)<<" "<<res<<endl;
	best = max(best, res);
	std::rotate(W.begin(), W.begin()+1, W.end());
    }
    
    return best;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>s;
    n *= 2;

    cout<<brute()<<endl;
    
       
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 44 ms 444 KB Output is correct
15 Correct 47 ms 384 KB Output is correct
16 Correct 51 ms 384 KB Output is correct
17 Correct 44 ms 384 KB Output is correct
18 Correct 46 ms 384 KB Output is correct
19 Correct 37 ms 384 KB Output is correct
20 Correct 38 ms 384 KB Output is correct
21 Correct 34 ms 384 KB Output is correct
22 Correct 35 ms 444 KB Output is correct
23 Correct 19 ms 384 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 31 ms 384 KB Output is correct
26 Correct 35 ms 384 KB Output is correct
27 Correct 38 ms 384 KB Output is correct
28 Correct 42 ms 504 KB Output is correct
29 Correct 34 ms 384 KB Output is correct
30 Correct 33 ms 384 KB Output is correct
31 Correct 43 ms 384 KB Output is correct
32 Correct 42 ms 384 KB Output is correct
33 Correct 40 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 44 ms 444 KB Output is correct
15 Correct 47 ms 384 KB Output is correct
16 Correct 51 ms 384 KB Output is correct
17 Correct 44 ms 384 KB Output is correct
18 Correct 46 ms 384 KB Output is correct
19 Correct 37 ms 384 KB Output is correct
20 Correct 38 ms 384 KB Output is correct
21 Correct 34 ms 384 KB Output is correct
22 Correct 35 ms 444 KB Output is correct
23 Correct 19 ms 384 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 31 ms 384 KB Output is correct
26 Correct 35 ms 384 KB Output is correct
27 Correct 38 ms 384 KB Output is correct
28 Correct 42 ms 504 KB Output is correct
29 Correct 34 ms 384 KB Output is correct
30 Correct 33 ms 384 KB Output is correct
31 Correct 43 ms 384 KB Output is correct
32 Correct 42 ms 384 KB Output is correct
33 Correct 40 ms 384 KB Output is correct
34 Execution timed out 2041 ms 928 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 44 ms 444 KB Output is correct
15 Correct 47 ms 384 KB Output is correct
16 Correct 51 ms 384 KB Output is correct
17 Correct 44 ms 384 KB Output is correct
18 Correct 46 ms 384 KB Output is correct
19 Correct 37 ms 384 KB Output is correct
20 Correct 38 ms 384 KB Output is correct
21 Correct 34 ms 384 KB Output is correct
22 Correct 35 ms 444 KB Output is correct
23 Correct 19 ms 384 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 31 ms 384 KB Output is correct
26 Correct 35 ms 384 KB Output is correct
27 Correct 38 ms 384 KB Output is correct
28 Correct 42 ms 504 KB Output is correct
29 Correct 34 ms 384 KB Output is correct
30 Correct 33 ms 384 KB Output is correct
31 Correct 43 ms 384 KB Output is correct
32 Correct 42 ms 384 KB Output is correct
33 Correct 40 ms 384 KB Output is correct
34 Execution timed out 2041 ms 928 KB Time limit exceeded
35 Halted 0 ms 0 KB -