답안 #235401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235401 2020-05-28T08:34:27 Z Charis02 Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 262148 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n;
string s,t;
map < string,bool > vis;
map < string,ll > steps;

void solve()
{
    queue < string > q;
    q.push(s);
    vis[s]=true;
    steps[s] = 0;

    while(!q.empty())
    {
        string cur = q.front();
        q.pop();

        string tmp = cur;
        rep(i,0,n)
        {
            tmp = cur;
            rep(j,i,n)
            {
                tmp[j] =  '1';
                if(!vis[tmp])
                {
                    vis[tmp]=true;
                    steps[tmp]=steps[cur]+1;
                    q.push(tmp);
                }
            }
        }
        rep(i,0,n)
        {
            tmp = cur;
            rep(j,i,n)
            {
                tmp[j] =  '0';
                if(!vis[tmp])
                {
                    vis[tmp]=true;
                    steps[tmp]=steps[cur]+1;
                    q.push(tmp);
                }
            }
        }
        rep(i,0,n)
        {
            tmp = cur;
            rep(j,i,n)
            {
                tmp[j] = ((tmp[j]-'0')+1)%2 + '0';
                if(!vis[tmp])
                {
                    vis[tmp]=true;
                    steps[tmp]=steps[cur]+1;
                    q.push(tmp);
                }
            }
        }
    }

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    cin >> s;
    cin >> t;

    solve();
    cout << steps[t];

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Execution timed out 1094 ms 15524 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Execution timed out 1094 ms 15524 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Runtime error 240 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Execution timed out 1094 ms 15524 KB Time limit exceeded
9 Halted 0 ms 0 KB -