답안 #865035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865035 2023-10-24T03:22:17 Z guagua0407 Lamps (JOI19_lamps) C++17
6 / 100
281 ms 102420 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s+ ".out").c_str(), "w", stdout);
}

const int mxn=1e6+5;
int a[mxn];
int dp[mxn];
vector<int> st[mxn],en[mxn];

int main() {_
    int n;
    cin>>n;
    string A,B;
    cin>>A>>B;
    int a=0,b=0;
    for(int i=0;i<n;i++){
        a+=(1<<(n-i-1))*(A[i]-'0');
    }
    for(int i=0;i<n;i++){
        b+=(1<<(n-i-1))*(B[i]-'0');
    }
    vector<int> dp(1<<n,1e9);
    vector<int> from(1<<n,-1);
    dp[a]=0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    pq.push({0,a});
    while(!pq.empty()){
        auto v=pq.top();
        //cout<<v.s<<'\n';
        pq.pop();
        if(v.f!=dp[v.s]) continue;
        for(int j=0;j<n;j++){
            {
                int val=v.s;
                for(int k=j;k<n;k++){
                        if(val&(1<<k)) val^=(1<<k);
                        if(dp[val]>dp[v.s]+1){
                            dp[val]=dp[v.s]+1;
                            pq.push({dp[val],val});
                        }
                }

            }
            {
                int val=v.s;
                for(int k=j;k<n;k++){
                        if(!(val&(1<<k))) val^=(1<<k);
                        if(dp[val]>dp[v.s]+1){
                            dp[val]=dp[v.s]+1;
                            pq.push({dp[val],val});
                        }
                }

            }
            {
                int val=v.s;
                for(int k=j;k<n;k++){
                        val^=(1<<k);
                        if(dp[val]>dp[v.s]+1){
                            dp[val]=dp[v.s]+1;
                            pq.push({dp[val],val});
                        }
                }

            }
        }
    }
    cout<<dp[b]<<'\n';
    /*while(b!=-1){
        for(int i=n-1;i>=0;i--){
            if(b&(1<<i)) cout<<1;
            else cout<<0;
        }
        cout<<'\n';
        b=from[b];
    }*/
    return 0;
}
//maybe its multiset not set
/*
16
0011001001000110
1101100100010101
*/

Compilation message

lamp.cpp: In function 'void setIO(std::string)':
lamp.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s+ ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Correct 10 ms 47580 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 10 ms 47792 KB Output is correct
5 Correct 12 ms 47704 KB Output is correct
6 Correct 10 ms 47960 KB Output is correct
7 Correct 10 ms 47708 KB Output is correct
8 Correct 264 ms 51920 KB Output is correct
9 Correct 265 ms 50976 KB Output is correct
10 Correct 132 ms 49376 KB Output is correct
11 Correct 131 ms 49876 KB Output is correct
12 Correct 267 ms 51968 KB Output is correct
13 Correct 139 ms 49880 KB Output is correct
14 Correct 268 ms 51976 KB Output is correct
15 Correct 133 ms 49880 KB Output is correct
16 Correct 275 ms 51916 KB Output is correct
17 Correct 128 ms 49872 KB Output is correct
18 Correct 263 ms 53028 KB Output is correct
19 Correct 128 ms 49884 KB Output is correct
20 Correct 268 ms 51924 KB Output is correct
21 Correct 130 ms 49884 KB Output is correct
22 Correct 270 ms 51916 KB Output is correct
23 Correct 124 ms 49876 KB Output is correct
24 Correct 268 ms 51916 KB Output is correct
25 Correct 126 ms 49876 KB Output is correct
26 Correct 270 ms 51916 KB Output is correct
27 Correct 125 ms 49880 KB Output is correct
28 Correct 63 ms 48864 KB Output is correct
29 Correct 281 ms 52168 KB Output is correct
30 Correct 126 ms 49884 KB Output is correct
31 Correct 63 ms 48860 KB Output is correct
32 Correct 279 ms 52064 KB Output is correct
33 Correct 133 ms 49884 KB Output is correct
34 Correct 63 ms 48980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Correct 10 ms 47580 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 10 ms 47792 KB Output is correct
5 Correct 12 ms 47704 KB Output is correct
6 Correct 10 ms 47960 KB Output is correct
7 Correct 10 ms 47708 KB Output is correct
8 Correct 264 ms 51920 KB Output is correct
9 Correct 265 ms 50976 KB Output is correct
10 Correct 132 ms 49376 KB Output is correct
11 Correct 131 ms 49876 KB Output is correct
12 Correct 267 ms 51968 KB Output is correct
13 Correct 139 ms 49880 KB Output is correct
14 Correct 268 ms 51976 KB Output is correct
15 Correct 133 ms 49880 KB Output is correct
16 Correct 275 ms 51916 KB Output is correct
17 Correct 128 ms 49872 KB Output is correct
18 Correct 263 ms 53028 KB Output is correct
19 Correct 128 ms 49884 KB Output is correct
20 Correct 268 ms 51924 KB Output is correct
21 Correct 130 ms 49884 KB Output is correct
22 Correct 270 ms 51916 KB Output is correct
23 Correct 124 ms 49876 KB Output is correct
24 Correct 268 ms 51916 KB Output is correct
25 Correct 126 ms 49876 KB Output is correct
26 Correct 270 ms 51916 KB Output is correct
27 Correct 125 ms 49880 KB Output is correct
28 Correct 63 ms 48864 KB Output is correct
29 Correct 281 ms 52168 KB Output is correct
30 Correct 126 ms 49884 KB Output is correct
31 Correct 63 ms 48860 KB Output is correct
32 Correct 279 ms 52064 KB Output is correct
33 Correct 133 ms 49884 KB Output is correct
34 Correct 63 ms 48980 KB Output is correct
35 Runtime error 45 ms 97508 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Correct 10 ms 47708 KB Output is correct
3 Correct 12 ms 47708 KB Output is correct
4 Correct 10 ms 47708 KB Output is correct
5 Correct 10 ms 47708 KB Output is correct
6 Correct 10 ms 47708 KB Output is correct
7 Runtime error 53 ms 102420 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Correct 10 ms 47580 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 10 ms 47792 KB Output is correct
5 Correct 12 ms 47704 KB Output is correct
6 Correct 10 ms 47960 KB Output is correct
7 Correct 10 ms 47708 KB Output is correct
8 Correct 264 ms 51920 KB Output is correct
9 Correct 265 ms 50976 KB Output is correct
10 Correct 132 ms 49376 KB Output is correct
11 Correct 131 ms 49876 KB Output is correct
12 Correct 267 ms 51968 KB Output is correct
13 Correct 139 ms 49880 KB Output is correct
14 Correct 268 ms 51976 KB Output is correct
15 Correct 133 ms 49880 KB Output is correct
16 Correct 275 ms 51916 KB Output is correct
17 Correct 128 ms 49872 KB Output is correct
18 Correct 263 ms 53028 KB Output is correct
19 Correct 128 ms 49884 KB Output is correct
20 Correct 268 ms 51924 KB Output is correct
21 Correct 130 ms 49884 KB Output is correct
22 Correct 270 ms 51916 KB Output is correct
23 Correct 124 ms 49876 KB Output is correct
24 Correct 268 ms 51916 KB Output is correct
25 Correct 126 ms 49876 KB Output is correct
26 Correct 270 ms 51916 KB Output is correct
27 Correct 125 ms 49880 KB Output is correct
28 Correct 63 ms 48864 KB Output is correct
29 Correct 281 ms 52168 KB Output is correct
30 Correct 126 ms 49884 KB Output is correct
31 Correct 63 ms 48860 KB Output is correct
32 Correct 279 ms 52064 KB Output is correct
33 Correct 133 ms 49884 KB Output is correct
34 Correct 63 ms 48980 KB Output is correct
35 Runtime error 45 ms 97508 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -