Submission #235405

# Submission time Handle Problem Language Result Execution time Memory
235405 2020-05-28T08:38:55 Z Charis02 Lamps (JOI19_lamps) C++14
6 / 100
305 ms 6868 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<unordered_map>
#include<set>
#include<algorithm>
#define ll int
#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;
bool vis[N];
int steps[N];

void solve()
{
    queue < int > q;
    int ss = 0;
    rep(i,0,n)
        ss += (s[i]-'0')*(1 << i);
    q.push(ss);
    vis[ss]=true;
    steps[ss] = 0;

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

        int tmp = cur;
        rep(i,0,n)
        {
            tmp = cur;
            rep(j,i,n)
            {
                tmp |= (1 << j);
                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 &= ~(1 << j);
                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 ^= (1 << j);
                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();
    int tt=0;
    rep(i,0,n)
        tt += (t[i]-'0')*(1<<i);
    cout << steps[tt];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 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 Correct 4 ms 384 KB Output is correct
8 Correct 277 ms 2144 KB Output is correct
9 Correct 288 ms 2040 KB Output is correct
10 Correct 117 ms 1152 KB Output is correct
11 Correct 120 ms 1272 KB Output is correct
12 Correct 278 ms 2204 KB Output is correct
13 Correct 126 ms 1280 KB Output is correct
14 Correct 269 ms 2040 KB Output is correct
15 Correct 127 ms 1280 KB Output is correct
16 Correct 287 ms 2168 KB Output is correct
17 Correct 122 ms 1280 KB Output is correct
18 Correct 305 ms 2224 KB Output is correct
19 Correct 124 ms 1272 KB Output is correct
20 Correct 285 ms 2168 KB Output is correct
21 Correct 127 ms 1400 KB Output is correct
22 Correct 272 ms 2308 KB Output is correct
23 Correct 129 ms 1280 KB Output is correct
24 Correct 286 ms 2040 KB Output is correct
25 Correct 124 ms 1400 KB Output is correct
26 Correct 290 ms 2168 KB Output is correct
27 Correct 123 ms 1400 KB Output is correct
28 Correct 56 ms 888 KB Output is correct
29 Correct 279 ms 2148 KB Output is correct
30 Correct 122 ms 1276 KB Output is correct
31 Correct 60 ms 768 KB Output is correct
32 Correct 272 ms 2044 KB Output is correct
33 Correct 120 ms 1280 KB Output is correct
34 Correct 57 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 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 Correct 4 ms 384 KB Output is correct
8 Correct 277 ms 2144 KB Output is correct
9 Correct 288 ms 2040 KB Output is correct
10 Correct 117 ms 1152 KB Output is correct
11 Correct 120 ms 1272 KB Output is correct
12 Correct 278 ms 2204 KB Output is correct
13 Correct 126 ms 1280 KB Output is correct
14 Correct 269 ms 2040 KB Output is correct
15 Correct 127 ms 1280 KB Output is correct
16 Correct 287 ms 2168 KB Output is correct
17 Correct 122 ms 1280 KB Output is correct
18 Correct 305 ms 2224 KB Output is correct
19 Correct 124 ms 1272 KB Output is correct
20 Correct 285 ms 2168 KB Output is correct
21 Correct 127 ms 1400 KB Output is correct
22 Correct 272 ms 2308 KB Output is correct
23 Correct 129 ms 1280 KB Output is correct
24 Correct 286 ms 2040 KB Output is correct
25 Correct 124 ms 1400 KB Output is correct
26 Correct 290 ms 2168 KB Output is correct
27 Correct 123 ms 1400 KB Output is correct
28 Correct 56 ms 888 KB Output is correct
29 Correct 279 ms 2148 KB Output is correct
30 Correct 122 ms 1276 KB Output is correct
31 Correct 60 ms 768 KB Output is correct
32 Correct 272 ms 2044 KB Output is correct
33 Correct 120 ms 1280 KB Output is correct
34 Correct 57 ms 768 KB Output is correct
35 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 436 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Runtime error 15 ms 6868 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 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 Correct 4 ms 384 KB Output is correct
8 Correct 277 ms 2144 KB Output is correct
9 Correct 288 ms 2040 KB Output is correct
10 Correct 117 ms 1152 KB Output is correct
11 Correct 120 ms 1272 KB Output is correct
12 Correct 278 ms 2204 KB Output is correct
13 Correct 126 ms 1280 KB Output is correct
14 Correct 269 ms 2040 KB Output is correct
15 Correct 127 ms 1280 KB Output is correct
16 Correct 287 ms 2168 KB Output is correct
17 Correct 122 ms 1280 KB Output is correct
18 Correct 305 ms 2224 KB Output is correct
19 Correct 124 ms 1272 KB Output is correct
20 Correct 285 ms 2168 KB Output is correct
21 Correct 127 ms 1400 KB Output is correct
22 Correct 272 ms 2308 KB Output is correct
23 Correct 129 ms 1280 KB Output is correct
24 Correct 286 ms 2040 KB Output is correct
25 Correct 124 ms 1400 KB Output is correct
26 Correct 290 ms 2168 KB Output is correct
27 Correct 123 ms 1400 KB Output is correct
28 Correct 56 ms 888 KB Output is correct
29 Correct 279 ms 2148 KB Output is correct
30 Correct 122 ms 1276 KB Output is correct
31 Correct 60 ms 768 KB Output is correct
32 Correct 272 ms 2044 KB Output is correct
33 Correct 120 ms 1280 KB Output is correct
34 Correct 57 ms 768 KB Output is correct
35 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -