Submission #15611001
Source Code Expand
#include <bits/stdc++.h>
#define x first
#define y second
#define int int long long // 2e9 & 9e18
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif
signed main() {
int n;
cin >> n;
string s;
cin >> s;
int i = 0;
int j = n - 1;
int cnt = 0;
while (i < n && j >= 0 && i < j) {
while (i < n && s[i] == 'R') {
++i;
}
while (j >= 0 && s[j] == 'W') {
--j;
}
if (i < n && j >= 0 && i < j) {
swap(s[i], s[j]);
cnt++;
}
}
cout << cnt << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Alter Altar |
| User | Norrius |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 1261 Byte |
| Status | AC |
| Exec Time | 5 ms |
| Memory | 3780 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | a01.txt, a02.txt, a03.txt |
| All | a01.txt, a02.txt, a03.txt, b04.txt, b05.txt, b06.txt, b07.txt, b08.txt, b09.txt, b10.txt, b11.txt, b12.txt, b13.txt, b14.txt, b15.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| a01.txt | AC | 5 ms | 3616 KiB |
| a02.txt | AC | 2 ms | 3564 KiB |
| a03.txt | AC | 2 ms | 3488 KiB |
| b04.txt | AC | 2 ms | 3608 KiB |
| b05.txt | AC | 3 ms | 3780 KiB |
| b06.txt | AC | 2 ms | 3612 KiB |
| b07.txt | AC | 3 ms | 3556 KiB |
| b08.txt | AC | 4 ms | 3612 KiB |
| b09.txt | AC | 4 ms | 3764 KiB |
| b10.txt | AC | 4 ms | 3724 KiB |
| b11.txt | AC | 4 ms | 3612 KiB |
| b12.txt | AC | 3 ms | 3668 KiB |
| b13.txt | AC | 3 ms | 3736 KiB |
| b14.txt | AC | 2 ms | 3616 KiB |
| b15.txt | AC | 3 ms | 3556 KiB |