# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
982659 | SmuggingSpun | JJOOII 2 (JOI20_ho_t2) | C++14 | 167 ms | 2768 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
const int lim = 2e5 + 5;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
int n, k;
string s;
namespace sub1{
void solve(){
int m = 1 << n, ans = INT_MAX;
string pat = string(k, 'J') + string(k, 'O') + string(k, 'I');
for(int mask = 0; mask < m; mask++){
string current = "";
for(int i = 0; i < n; i++){
if(1 << i & mask){
current += s[i];
}
}
if(current == pat){
int l = 0, r = n - 1;
while((1 << l & mask) == 0){
l++;
}
while((1 << r & mask) == 0){
r--;
}
int cnt = 0;
for(int i = l; i <= r; i++){
if((1 << i & mask) == 0){
cnt++;
}
}
minimize(ans, cnt);
}
}
cout << (ans == INT_MAX ? -1 : ans);
}
}
namespace sub23{
vector<int>p[3];
int nxt[lim][3];
void solve(){
for(int i = 0; i < n; i++){
if(s[i] == 'J'){
p[0].emplace_back(i);
}
else if(s[i] == 'O'){
p[1].emplace_back(i);
}
else{
p[2].emplace_back(i);
}
}
memset(nxt, -1, sizeof(nxt));
for(int i = 0; i < 3; i++){
for(int j = 0, pos = 0; j < n && pos + k - 1 < p[i].size(); j++){
nxt[j][i] = p[i][pos + k - 1];
if(p[i][pos + k - 1] == j){
pos++;
}
}
}
int ans = INT_MAX;
for(int i = 0; i + 3 * k <= n; i++){
int current = i;
for(int j = 0; j < 3; j++){
if((current = nxt[current][j]) == -1){
break;
}
}
if(current != -1){
minimize(ans, current - i - 3 * k + 1);
}
}
cout << (ans == INT_MAX ? -1 : ans);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> k >> s;
if(n <= 21){
sub1::solve();
}
else{
sub23::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |