답안 #792344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792344 2023-07-25T01:58:10 Z 1075508020060209tc Crtanje (COCI20_crtanje) C++14
50 / 50
1 ms 340 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
//#pragma GCC target("popcnt")
using namespace std;
#define int long long
int n;
string s;
int ar[200005];
int ps[200005];
int chmn;
int chmx;
string ans[500];
signed main()
{

    cin>>n>>s;
    for(int i=1;i<=300;i++){
        ans[i]="*";
        for(int j=1;j<=n;j++){
            ans[i]+=".";
        }
    }

    s="*"+s;
    chmn=0;
    chmx=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='='){
            ps[i]=ps[i-1];
        }
        if(s[i]=='+'){
            ps[i]=ps[i-1]+1;
        }
        if(s[i]=='-'){
            ps[i]=ps[i-1]-1;
        }
        if(i==n){continue;}
        chmn=min(chmn,ps[i]);
        chmx=max(chmx,ps[i]);
    }
    int nwx=chmx+1;
    if(s[1]=='='){ans[nwx][1]='_';}
    if(s[1]=='+'){ans[nwx][1]='/';}
    if(s[1]=='-'){ans[nwx][1]='a'-5;}
    for(int i=2;i<=n;i++){
        if(s[i]=='='){
            if(s[i-1]=='='||s[i-1]=='-'){
                ans[nwx][i]='_';
            }else{
                ans[--nwx][i]='_';
            }
        }
        if(s[i]=='+'){
            if(s[i-1]=='+'){
                ans[--nwx][i]='/';
            }else{
                ans[nwx][i]='/';
            }
        }
        if(s[i]=='-'){
            if(s[i-1]=='-'||s[i-1]=='='){
                ans[++nwx][i]='a'-5;
            }else{
                ans[nwx][i]='a'-5;
            }
        }
    }

    for(int i=1;i<=chmx-chmn+1;i++){
        int ok=0;
        for(int j=1;j<=n;j++){
            if(ans[i][j]!='.'){ok=1;}
        }
        if(!ok){continue;}
        for(int j=1;j<=n;j++){
            cout<<ans[i][j];
        }cout<<endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct