답안 #376148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376148 2021-03-11T02:00:42 Z daniel920712 Lamps (JOI19_lamps) C++14
0 / 100
612 ms 262148 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <queue>

using namespace std;
char a[1000005];
char b[1000005];
bool have[1000005]={0};
int DP[1000005],N;
bool vis[1000005]={0};
queue < pair < int , int > > BFS;
int F(int here)
{
    int i,tt;
    if(here==N) return 0;
    if(have[here]) return DP[here];
    have[here]=1;
    if(a[here]==b[here]) DP[here]=F(here+1);
    else DP[here]=F(here+1)+1;
    tt=0;
    for(i=here;i<N;i++)
    {
        if(b[i]=='1'&&(i==here||b[i-1]=='0')) tt++;
        DP[here]=min(DP[here],F(i+1)+tt+1);
    }
    tt=0;
    for(i=here;i<N;i++)
    {
        if(b[i]=='0'&&(i==here||b[i-1]=='1')) tt++;
        DP[here]=min(DP[here],F(i+1)+tt+1);
    }
    tt=0;
    for(i=here;i<N;i++)
    {
        if(a[i]==b[i]&&(i==here||a[i-1]!=b[i-1])) tt++;
        DP[here]=min(DP[here],F(i+1)+tt+1);

    }
    return DP[here];

}
int main()
{
    int M,ans=0,i,j,x=0,y=0,aa,tt;
    scanf("%d",&N);
    scanf("%s %s",a,b);
    x=y=0;
    for(i=0;i<N;i++)
    {
        x*=2;
        x+=a[i]-'0';
        y*=2;
        y+=b[i]-'0';
    }

    BFS.push(make_pair(x,0));
    while(!BFS.empty())
    {
        x=BFS.front().first;
        aa=BFS.front().second;
        BFS.pop();
        if(vis[x]) continue;
        vis[x]=1;
        //printf("%d %d %d\n",x,y,aa);
        if(x==y)
        {
            printf("%d\n",aa);
            return 0;
        }
        tt=0;
        for(i=0;i<N;i++)
        {
            tt=x;
            for(j=i;j<N;j++)
            {
                if(tt&(1<<j)) tt-=1<<j;
                BFS.push(make_pair(tt,aa+1));
            }
        }

        for(i=0;i<N;i++)
        {
            tt=x;
            for(j=i;j<N;j++)
            {
                if(!(tt&(1<<j))) tt+=1<<j;
                BFS.push(make_pair(tt,aa+1));
            }
        }

        for(i=0;i<N;i++)
        {
            tt=x;
            for(j=i;j<N;j++)
            {
                if(!(tt&(1<<j))) tt+=1<<j;
                else tt-=1<<j;
                BFS.push(make_pair(tt,aa+1));
            }
        }


    }
    //printf("%d\n",F(0));
    return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:45:9: warning: unused variable 'M' [-Wunused-variable]
   45 |     int M,ans=0,i,j,x=0,y=0,aa,tt;
      |         ^
lamp.cpp:45:11: warning: unused variable 'ans' [-Wunused-variable]
   45 |     int M,ans=0,i,j,x=0,y=0,aa,tt;
      |           ^~~
lamp.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
lamp.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%s %s",a,b);
      |     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Runtime error 612 ms 262148 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Runtime error 612 ms 262148 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 12 ms 3436 KB Output is correct
8 Runtime error 475 ms 262148 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Runtime error 612 ms 262148 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -