Submission #427205

#TimeUsernameProblemLanguageResultExecution timeMemory
427205vincentpikachu20Paint By Numbers (IOI16_paint)C++17
32 / 100
1 ms204 KiB
#include "paint.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;

string solve_puzzle(string s, vector<signed> c) {
    int n = s.size(), k = c.size();
    string ans = s;
    vector<int> l(k),r(k);
    //put all to the lefts
    int p = 0;
    for(int i = 0; i < k; i ++){
        bool okay;
        do{
            okay = true; int mine = 0;
            for(int j = p; j < p + c[i]; j ++){
                if(s[j] == '_'){ okay = false; mine = j; break; }
            }
            if(okay){ r[i] = p + c[i]; p += c[i] + 1; }
            else p = mine + 1;
        }while(!okay);
    }
    //put all to the rights
    p = n;
    for(int i = k-1; i >= 0; i --){
        bool okay;
        do{
            okay = true; int mine = 0;
            for(int j = p-1; j >= p-c[i]; j --){
                if(s[j] == '_'){ okay = false; mine = j; break; }
            }
            if(okay){ l[i] = p - c[i]; p -= c[i] + 1; }
            else p = mine;
        }while(!okay);
    }
    //apply x's
    for(int i = 0; i < k; i ++){
        for(int j = l[i]; j < r[i]; j ++) ans[j] = 'X';
    }
    //clean up?
    bool vague = false; char prev = '_';
    for(int i = 0; i < n; i ++){
        if(prev == '_' && ans[i] == '_'){}
        else if(prev == '_' && ans[i] == 'X'){ vague = false; }
        else if(prev == '_' && ans[i] == '.'){ vague = true; ans[i] = '?'; }
        else if(prev == 'X' && ans[i] == '_'){}
        else if(prev == 'X' && ans[i] == 'X'){}
        else if(prev == 'X' && ans[i] == '.'){ ans[i] = (vague ? '?' : '_'); }
        else if(prev == '?' && ans[i] == '_'){}
        else if(prev == '?' && ans[i] == 'X'){}
        else if(prev == '?' && ans[i] == '.'){ ans[i] = '?'; }
        prev = ans[i];
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...