Submission #473766

#TimeUsernameProblemLanguageResultExecution timeMemory
473766Ahmed_SolymanCrtanje (COCI20_crtanje)C++14
20 / 50
4 ms844 KiB
#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(n,vector<char>(n,'.')); for(ll start=0;start<n;start++){ ll prev=-1; vector<vector<char>>temp(n,vector<char>(n,'.')); 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--; else if(s[i]=='='){ if(c=='+')x--; else if(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<n;i++){ bool b=0; for(ll j=0;j<n;j++){ b|=(ans[i][j]!='.'); } if(!b){ for(ll j=0;j<n;j++){ un_valid[{i,j}]=1; } } } for(ll i=0;i<n;i++){ bool b=0; for(ll j=0;j<n;j++){ b|=(ans[j][i]!='.'); } if(!b){ for(ll j=0;j<n;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 timeMemoryGrader output
Fetching results...