답안 #501974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501974 2022-01-05T03:45:55 Z amunduzbaev Monochrome Points (JOI20_monochrome) C++14
0 / 100
1 ms 316 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	string s; cin>>s;
	vector<ar<int, 2>> a(n);
	for(int l = 0, r = n - 1, i=0;i<2*n;i++){
		if(s[i] == 'B') a[l][0] = i, l++;
		else a[r][1] = i, r--;
	}
	
	auto check = [&](ar<int, 2> a, ar<int, 2> b){
		if(a[0] > a[1]) swap(a[0], a[1]);
		if(b[0] > b[1]) swap(b[0], b[1]);
		if(a[0] <= b[0] && b[1] <= a[1]) return false;
		if(b[0] <= a[0] && a[1] <= b[1]) return false;
		return (max(a[0], b[0]) <= min(a[1], b[1]));
	};
	
	for(int i=0;i<n;i++){
		bool ok = (a[i][0] <= a[i][1]);
		for(int j=i+1;j<n;j++){
			if(ok && a[j][0] <= a[j][1] && a[j][1] <= a[i][1]){
				swap(a[j][1], a[i][1]);
			} if(!ok && a[j][0] >= a[j][1] && a[i][1] >= a[j][1]){
				swap(a[j][1], a[i][1]);
			}
		}
	}

	int res = 0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			res += check(a[i], a[j]);
		}
	} 
	
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -