답안 #865034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865034 2023-10-24T03:20:03 Z guagua0407 Lamps (JOI19_lamps) C++17
0 / 100
166 ms 262144 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> adj[1<<n];
    //return 0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            {
                int val=i;
                for(int k=j;k<n;k++){
                        if(val&(1<<k)) val^=(1<<k);
                        adj[i].push_back(val);
                }

            }
            {
                int val=i;
                for(int k=j;k<n;k++){
                        if(!(val&(1<<k))) val^=(1<<k);
                        adj[i].push_back(val);
                }

            }
            {
                int val=i;
                for(int k=j;k<n;k++){
                        val^=(1<<k);
                        adj[i].push_back(val);
                }

            }
        }
    }
    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(auto u:adj[v.s]){
            if(dp[u]>dp[v.s]+1){
                dp[u]=dp[v.s]+1;
                from[u]=v.s;
                pq.push({dp[u],u});
            }
        }
    }
    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 12 ms 47828 KB Output is correct
2 Correct 10 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 11 ms 47708 KB Output is correct
5 Correct 11 ms 47704 KB Output is correct
6 Correct 10 ms 47704 KB Output is correct
7 Correct 11 ms 47708 KB Output is correct
8 Runtime error 166 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 47828 KB Output is correct
2 Correct 10 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 11 ms 47708 KB Output is correct
5 Correct 11 ms 47704 KB Output is correct
6 Correct 10 ms 47704 KB Output is correct
7 Correct 11 ms 47708 KB Output is correct
8 Runtime error 166 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 47704 KB Output is correct
2 Correct 10 ms 47708 KB Output is correct
3 Correct 10 ms 47704 KB Output is correct
4 Correct 11 ms 47708 KB Output is correct
5 Correct 10 ms 47708 KB Output is correct
6 Correct 10 ms 47792 KB Output is correct
7 Runtime error 124 ms 262144 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 47828 KB Output is correct
2 Correct 10 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 11 ms 47708 KB Output is correct
5 Correct 11 ms 47704 KB Output is correct
6 Correct 10 ms 47704 KB Output is correct
7 Correct 11 ms 47708 KB Output is correct
8 Runtime error 166 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -