Submission #865034

#TimeUsernameProblemLanguageResultExecution timeMemory
865034guagua0407Lamps (JOI19_lamps)C++17
0 / 100
166 ms262144 KiB
//#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 (stderr)

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...