Submission #312450

#TimeUsernameProblemLanguageResultExecution timeMemory
312450talant117408Paint By Numbers (IOI16_paint)C++17
32 / 100
1 ms384 KiB
#include "paint.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

string solve_puzzle(string s, vector<int> c) {
    string res = "";
    string a = "", b = "";
    int pos = 0, i, clues = sz(c), j, n = sz(s);
    vector <pii> borders(clues);
    
    for(i = 0; i < n; i++){
        a += '.';
        b += '.';
        res += '?';
    }
    
    for(i = 0; i < clues; i++){
        int flag = -1;
        while(pos < n && s[pos] == '_') pos++;
        for(j = pos; j < pos+c[i]; j++){
            if(s[j] == '_') flag = j;
        }
        if(flag == -1){
            for(j = pos; j < pos+c[i]; j++){
                a[j] = 'X';
            }
            borders[i].first = pos;
            pos += c[i]+1;
        }
        else{
            i--;
            pos = flag+1;
        }
    }
    
    pos = n-1;
    for(i = clues-1; i >= 0; i--){
        int flag = -1;
        while(pos >= 0 && s[pos] == '_') pos--;
        for(j = pos; j > pos-c[i]; j--){
            if(s[j] == '_') flag = j;
        }
        if(flag == -1){
            for(j = pos; j > pos-c[i]; j--){
                b[j] = 'X';
            }
            borders[i].second = pos-c[i]+1;
            pos -= (c[i]+1);
        }
        else{
            i++;
            pos = flag-1;
        }
    }
    
    for(i = 0; i < n; i++){
        if(s[i] == '_'){
            res[i] = '_';
        }
    }
    
    for(i = 0; i < clues; i++){
        int l = borders[i].first, r = borders[i].second;
        for(j = r; j < l+c[i]; j++){
            res[j] = 'X';
        }
        borders[i].first = r;
        borders[i].second = l+c[i];
    }
    
    for(i = 0; i < clues-1; i++){
        int l1 = borders[i].first, r1 = borders[i].second;
        int l2 = borders[i+1].first, r2 = borders[i+1].second;
        
        if(l1 < r1 && l2 < r2 && abs(r1-l2) < 2){
            res[r1] = '_';
        }
    }
    
    return res;
}
#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...