답안 #55667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55667 2018-07-08T12:19:04 Z leehosu01 게임판 (CEOI13_board) C++17
70 / 100
200 ms 892 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
class IB{
public:
    bitset<101111>NB;
    int DE;
    IB(){DE=0;NB.reset();}
    void operator<<(int n){for(;n--;DE++)NB.reset(DE);}
    void operator>>(int n){for(;n--;DE--)NB.reset(DE-1);}
    void operator++()
    {
        int i;
        for(i=DE-1;i>=0;i--)
            if(NB.test(i))
                NB.reset(i);
            else break;
        if(i==-1)NB.set(0),NB.reset(DE),DE++;
        else NB.set(i);
    }
    void operator--()
    {
        int i;
        for(i=DE-1;i>=0;i--)
            if(!NB.test(i))
                NB.set(i);
            else break;
        if(i==-1)NB.reset(DE-1),DE--;
        else NB.reset(i);
    }
    bool operator< (const IB&X)const
    {
        for(int i=0;i<max(DE,X.DE);i++)
            if(NB.test(i)!=X.NB.test(i))
                return X.NB.test(i);
        return 0;
    }
}tr[2];
ll mi=1<<30;
ll pro(int l)
{
    static ll T=0;
    static int i=0;
   // cout<<T<<i<<'\n';
    for(;i<l;i++)
    {
        T<<=1;
        T+=tr[1].NB.test(i);
        T-=tr[0].NB.test(i);
    }
    return T;
}
void rand(string &SS)
{
    SS.clear();int TT,DWC=0;
    for(int i=0;i<100000;i++)
    {
        do TT=rand()%3;while(TT==2&&!DWC);
        if(TT<2)DWC++;
        if(TT==2)DWC--;
        SS+="12ULR"[TT];
    }
}
int main()
{
    srand(time(NULL)*124124ll^24553);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S;
    for(int i=0;i<=1;i++)
    {
        //ra0nd(S);
        cin>>S;
        string T;
        for(int j=0;j<S.size();j++)
        {
            if(!T.empty()&&(T.back()=='R'&&S[j]=='L'||T.back()=='L'&&S[j]=='R'))T.resize(T.size()-1);\
            else T+=S[j];
        }
        for(auto&I:T)
        {
            if(I=='1')tr[i]<<1;
            else if(I=='2')tr[i]<<1,++tr[i];
            else if(I=='U')tr[i]>>1;
            else if(I=='L')--tr[i];
            else if(I=='R')++tr[i];
        }
    }
    int i;
    if(tr[1].DE<tr[0].DE)swap(tr[0],tr[1]);
    if(tr[1]<tr[0])swap(tr[0],tr[1]);
    for(i=0;i<=tr[1].DE;i++)
    {
  	    ll TP=pro(i);
        mi=min(mi,abs(i-tr[0].DE)+abs(i-tr[1].DE)+TP);
      	if(TP>mi)break;
    }
    cout<<mi;
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<S.size();j++)
                     ~^~~~~~~~~
board.cpp:77:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
             if(!T.empty()&&(T.back()=='R'&&S[j]=='L'||T.back()=='L'&&S[j]=='R'))T.resize(T.size()-1);\
                             ~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
3 Correct 6 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 776 KB Output is correct
2 Correct 2 ms 776 KB Output is correct
3 Correct 3 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 776 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 2 ms 876 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 3 ms 876 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 876 KB Output is correct
2 Correct 3 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 2 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 876 KB Output is correct
2 Correct 16 ms 892 KB Output is correct
3 Correct 5 ms 892 KB Output is correct
4 Correct 2 ms 892 KB Output is correct
5 Correct 3 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -