Submission #615698

#TimeUsernameProblemLanguageResultExecution timeMemory
615698ACGNPaint By Numbers (IOI16_paint)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
const int inf = 1e9;
bool cr(string& s,vi& tg) {
    //cout<<s<<endl;
    int cs = 0;
    int tgp = 0;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='.') {
            cs++;
            if (cs==tg[tgp]) {
                cs=-1;tgp++;
                if (tgp==tg.size()) return 1;
            }
        }
        else cs=0;
    }
    return 0;

}

vi crfront(string& s,vi& tg) {
    int cs = 0;
    int tgp = 0;
    vi csr(tg.size()+1,inf);
    csr[0]=-1;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='.') {
            cs++;
            if (cs==tg[tgp]) {
                cs=-1;tgp++;csr[tgp]=i+1;
                if (tgp==tg.size()) return csr;
            }
        }
        else cs=0;
    }
    return csr;
}
vi crback(string& s,vi& tg) {
    int cs = 0;
    int tgp = tg.size()-1;
    vi csr(tg.size()+1,-inf);csr[tg.size()]=s.size();
    for (int i=s.size()-1;i>=0;i--) {
        if (s[i]=='.') {
            cs++;
            if (cs==tg[tgp]) {
                cs=-1;csr[tgp]=i-1;tgp--;
                if (tgp==-1) return csr;
            }
        }
        else cs=0;
    }
    return csr;
}

void solve() {
    string s;cin>>s;
    int m;cin>>m;
    vi v;
    int n = s.size();
    for (int i=0;i<m;i++) {
        int z;cin>>z;
        v.pb(z);
    }
    string s1=s,s2=s,sf=s;
    for (int i=0;i<n;i++) {
        if (s[i]=='.') {
            s1[i]='_';
            if (cr(s1,v)) s2[i]='_';
            s1[i]='.'; 
        }
    }
    vi v1=crfront(s,v),v2=crback(s,v);
    //for (int i=0;i<=m;i++) cout<<v1[i]<<" ";cout<<endl;
    //for (int i=0;i<=m;i++) cout<<v2[i]<<" ";cout<<endl;
    for (int i=0;i<n;i++) {
        if (s[i]=='_') cout<<'_';
        else {
            int canw = (s2[i]=='_');
            int canb = 0;
            for (int j=0;j<m;j++) {
                int p1 = v1[j],p2=v2[j+1];
                int gr=1;
                if (p1>=i) continue;
                if (p2<=i) continue;
                for (int q=i+1;q<p2;q++) {
                    if (s[q]=='_') break;
                    gr++;
                }
                for (int q=i-1;q>p1;q--) {
                    if (s[q]=='_') break;
                    gr++;
                }
                //cout<<j<<" "<<gr<<endl;   
                if (gr>=v[j]) canb=2;
            }
            switch(canb+canw) {
                case 1:
                cout<<'_';break;
                case 2:
                cout<<'X';break;
                case 3:
                cout<<'?';break;
            }
        }
    }

    
        
}

signed main() {
    solve();
}

Compilation message (stderr)

paint.cpp: In function 'bool cr(std::string&, std::vector<int>&)':
paint.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i=0;i<s.size();i++) {
      |                  ~^~~~~~~~~
paint.cpp:15:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |                 if (tgp==tg.size()) return 1;
      |                     ~~~^~~~~~~~~~~
paint.cpp: In function 'std::vector<int> crfront(std::string&, std::vector<int>&)':
paint.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0;i<s.size();i++) {
      |                  ~^~~~~~~~~
paint.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                 if (tgp==tg.size()) return csr;
      |                     ~~~^~~~~~~~~~~
/usr/bin/ld: /tmp/cc0AuXqG.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccYChPYE.o:paint.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc0AuXqG.o: in function `main':
grader.cpp:(.text.startup+0x20b): undefined reference to `solve_puzzle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status