Submission #473777

# Submission time Handle Problem Language Result Execution time Memory
473777 2021-09-16T08:49:17 Z Ahmed_Solyman Crtanje (COCI20_crtanje) C++14
50 / 50
171 ms 16224 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n;
ll valid(ll i){
    if(i>=0 && i<n)return 1;
    return 0;
}
char con(char c){
    if(c=='+')return '/';
    else if(c=='-')return 92;
    else return '_';
}
int main()
{
    cin>>n;
    string s;cin>>s;
    vector<vector<char>>ans(500,vector<char>(500,'.'));
    for(ll start=0;start<n;start++){
        ll prev=-1;
        vector<vector<char>>temp(500,vector<char>(500,'.'));
        bool b=1;
        char c;
        for(ll i=0;i<n;i++){
            if(prev==-1){
                temp[start][i]=con(s[i]);
                prev=start;
                c=s[i];
            }
            else{
                ll x=0;
                if(s[i]=='-' && c!='+')x++;
                else if(s[i]!='-' && c=='+')x--;
                ll j=prev+x;
                if(!valid(j)){
                    b=0;
                    break;
                }
                else{
                    temp[j][i]=con(s[i]);
                    prev=j;
                    c=s[i];
                }
            }
        }
        if(b){
            ans=temp;
            break;
        }
    }
    map<pair<ll,ll>,bool>un_valid;
    for(ll i=0;i<500;i++){
        bool b=0;
        for(ll j=0;j<500;j++){
            b|=(ans[i][j]!='.');
        }
        if(!b){
            for(ll j=0;j<500;j++){
                un_valid[{i,j}]=1;
            }
        }
    }
    for(ll i=0;i<500;i++){
        bool b=0;
        for(ll j=0;j<500;j++){
            b|=(ans[j][i]!='.');
        }
        if(!b){
            for(ll j=0;j<500;j++){
                un_valid[{j,i}]=1;
            }
        }
    }
    for(ll i=0;i<n;i++){
        bool b=0;
        for(ll j=0;j<n;j++){
            if(un_valid[{i,j}]){
                continue;
            }
            b=1;
            cout<<ans[i][j];
        }
        if(b)cout<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 156 ms 16204 KB Output is correct
2 Correct 156 ms 16224 KB Output is correct
3 Correct 171 ms 16172 KB Output is correct
4 Correct 159 ms 16192 KB Output is correct
5 Correct 142 ms 16176 KB Output is correct