結果

問題 No.232 めぐるはめぐる (2)
ユーザー ngtkanangtkana
提出日時 2020-04-06 00:18:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 1,000 ms
コード長 1,465 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 201,944 KB
最終ジャッジ日時 2025-01-09 14:28:31
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
lint cabs(lint&x){return x<0?x=-x,1:0;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint T,x,y;std::cin>>T>>x>>y;
    std::swap(x,y);
    lint sx=cabs(x),sy=cabs(y);
    if(x==0&&y==0&&T==1||T<std::max(x,y)){
        std::cout<<"NO"<<'\n';
        return 0;
    }
    lint sxy=x>y?std::swap(x,y),1:0;
    std::vector<std::string>ans;
    auto mvchar=[&](char c){
        if(c=='<')x++;
        if(c=='>')x--;
        if(c=='v')y++;
        if(c=='^')y--;
    };
    auto mvstr=[&](std::string const&s){
        T--;
        for(char c:s)mvchar(c);
        ans.push_back(s);
    };
    while(T){
        using vec=std::vector<std::string>;
        vec v=(T-std::max(x,y))%2
            ?(x?vec{"^",">"}:y?vec{"^<",">"}:vec{"^>","v","<"})
            :(x?vec{"^>"}:y?vec{"^"}:vec{"^","v"});
        assert(0<=x&&0<=y);
        for(std::string&s:v)mvstr(s);
    }
    auto replace=[&](char&c,char c0,char c1){
        if(c==c0)c=c1;
        else if(c==c1)c=c0;
    };
    for(auto&&s:ans)for(char&c:s){
        if(sx)replace(c,'<','>');
        if(sy)replace(c,'v','^');
        if(sxy){
            replace(c,'^','>');
            replace(c,'v','<');
        }
    }
    std::cout<<"YES"<<'\n';
    for(auto&&s:ans){
        std::cout<<s<<'\n';
    }
}
0