답안 #631945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631945 2022-08-19T08:00:08 Z radal Lamps (JOI19_lamps) C++17
6 / 100
318 ms 21580 KB
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define pb push_back
#define X first
#define Y second
#define debug(x) cerr << #x << " : " << x << endl;
#define all(x) x.begin() , x.end()

using namespace std;

typedef pair<int,int> pll;
typedef long long ll;

constexpr int N = 3e5+10;

int d[N],pr[N][19],n,a,b;

void bfs(){
    queue<int> q;
    q.push(a);    
    d[a] = 0;
    while (!q.empty()){
        int v = q.front();
        if (v == b) break;
        q.pop();
        rep(l,0,n){
            rep(r,l,n){
                int s = pr[v][r],pw = (1 << (r+1))-(1 << l);
                if (l) s -= pr[v][l-1];
                if (d[v-s] > d[v]+1){
                    d[v-s] = d[v]+1;
                    q.push(v-s);
                }
                if (d[v+pw-s] > d[v]+1){
                    d[v+pw-s] = d[v]+1;
                    q.push(v+pw-s);
                }
                if (d[v+pw-2*s] > d[v]+1){
                    d[v+pw-2*s] = d[v]+1;
                    q.push(v+pw-2*s);
                }
            }
        }
    }
}
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(0);
    memset(d,63,sizeof d);
    string s,t;
    cin >> n >> s >> t;
    rep(i,0,n){
        if (s[i] == '1') a += (1 << i);
        if (t[i] == '1') b += (1 << i);
    }
    int y = (1 << n);
    rep(i,1,y){
        rep(j,0,n){
            if (!j){
                if (i&1) pr[i][j] = 1;
                continue;
            }
            if (i&(1 << j)) pr[i][j] = pr[i][j-1]+(1 << j);
            else pr[i][j] = pr[i][j-1];
        }
    }
    bfs();
    cout << d[b];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1452 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 203 ms 21400 KB Output is correct
9 Correct 208 ms 21392 KB Output is correct
10 Correct 82 ms 11448 KB Output is correct
11 Correct 82 ms 11452 KB Output is correct
12 Correct 39 ms 21228 KB Output is correct
13 Correct 77 ms 11536 KB Output is correct
14 Correct 45 ms 21352 KB Output is correct
15 Correct 60 ms 11516 KB Output is correct
16 Correct 99 ms 21420 KB Output is correct
17 Correct 40 ms 11516 KB Output is correct
18 Correct 54 ms 21428 KB Output is correct
19 Correct 29 ms 11420 KB Output is correct
20 Correct 156 ms 21580 KB Output is correct
21 Correct 15 ms 11320 KB Output is correct
22 Correct 80 ms 21460 KB Output is correct
23 Correct 89 ms 11492 KB Output is correct
24 Correct 29 ms 21068 KB Output is correct
25 Correct 13 ms 11296 KB Output is correct
26 Correct 134 ms 21524 KB Output is correct
27 Correct 53 ms 11464 KB Output is correct
28 Correct 15 ms 6492 KB Output is correct
29 Correct 165 ms 21476 KB Output is correct
30 Correct 49 ms 11476 KB Output is correct
31 Correct 7 ms 6372 KB Output is correct
32 Correct 38 ms 21332 KB Output is correct
33 Correct 50 ms 11400 KB Output is correct
34 Correct 21 ms 6388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1452 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 203 ms 21400 KB Output is correct
9 Correct 208 ms 21392 KB Output is correct
10 Correct 82 ms 11448 KB Output is correct
11 Correct 82 ms 11452 KB Output is correct
12 Correct 39 ms 21228 KB Output is correct
13 Correct 77 ms 11536 KB Output is correct
14 Correct 45 ms 21352 KB Output is correct
15 Correct 60 ms 11516 KB Output is correct
16 Correct 99 ms 21420 KB Output is correct
17 Correct 40 ms 11516 KB Output is correct
18 Correct 54 ms 21428 KB Output is correct
19 Correct 29 ms 11420 KB Output is correct
20 Correct 156 ms 21580 KB Output is correct
21 Correct 15 ms 11320 KB Output is correct
22 Correct 80 ms 21460 KB Output is correct
23 Correct 89 ms 11492 KB Output is correct
24 Correct 29 ms 21068 KB Output is correct
25 Correct 13 ms 11296 KB Output is correct
26 Correct 134 ms 21524 KB Output is correct
27 Correct 53 ms 11464 KB Output is correct
28 Correct 15 ms 6492 KB Output is correct
29 Correct 165 ms 21476 KB Output is correct
30 Correct 49 ms 11476 KB Output is correct
31 Correct 7 ms 6372 KB Output is correct
32 Correct 38 ms 21332 KB Output is correct
33 Correct 50 ms 11400 KB Output is correct
34 Correct 21 ms 6388 KB Output is correct
35 Runtime error 318 ms 12816 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 5 ms 3952 KB Output is correct
8 Runtime error 12 ms 8952 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1452 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 203 ms 21400 KB Output is correct
9 Correct 208 ms 21392 KB Output is correct
10 Correct 82 ms 11448 KB Output is correct
11 Correct 82 ms 11452 KB Output is correct
12 Correct 39 ms 21228 KB Output is correct
13 Correct 77 ms 11536 KB Output is correct
14 Correct 45 ms 21352 KB Output is correct
15 Correct 60 ms 11516 KB Output is correct
16 Correct 99 ms 21420 KB Output is correct
17 Correct 40 ms 11516 KB Output is correct
18 Correct 54 ms 21428 KB Output is correct
19 Correct 29 ms 11420 KB Output is correct
20 Correct 156 ms 21580 KB Output is correct
21 Correct 15 ms 11320 KB Output is correct
22 Correct 80 ms 21460 KB Output is correct
23 Correct 89 ms 11492 KB Output is correct
24 Correct 29 ms 21068 KB Output is correct
25 Correct 13 ms 11296 KB Output is correct
26 Correct 134 ms 21524 KB Output is correct
27 Correct 53 ms 11464 KB Output is correct
28 Correct 15 ms 6492 KB Output is correct
29 Correct 165 ms 21476 KB Output is correct
30 Correct 49 ms 11476 KB Output is correct
31 Correct 7 ms 6372 KB Output is correct
32 Correct 38 ms 21332 KB Output is correct
33 Correct 50 ms 11400 KB Output is correct
34 Correct 21 ms 6388 KB Output is correct
35 Runtime error 318 ms 12816 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -