WA in Div 3 950 C) Sofia and the Lost Operations

Revision en1, by aditya_patil71, 2024-06-20 18:36:35

Actually trying to generate the sequence.

My Code -> ~~~~~

# include <bits/stdc++.h>

using namespace std;

# define no "NO\n"

signed main(){ ios::sync_with_stdio(false);cin.tie(NULL);

# ifndef ONLINE_JUDGE

freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

# endif

int t; cin>>t; while( t-- ){ int n,m; cin>>n; vi a(n),b(n); loop(i,0,n)cin>>a[i]; loop(i,0,n)cin>>b[i]; cin>>m; vi d(m); loop(i,0,m)cin>>d[i]; // input ...

// checking for last value in d array,  if present in b array ....
int val = d.back(),ind=-1;
loop(i,0,n){
if( val == b[i] ){
ind=i;
break;
}
}
// if not present then no sequence possible ...
if( ind == -1 ){
cout<<no;
continue;
}
// mp[val] stores indices in a array for b[i]= val & b[i]!=a[i]
map<int,vector<int>> mp;
rloop(i,n-1,0){
if( a[i] != b[i] && (i != ind )){
mp[b[i]].push_back(i);
}
}

loop(i,0,m){
// replace d[i] at position where a[i] != b[i]
if( mp.count(d[i]) && mp[d[i]].size() > 0 ){
a[(mp[d[i]]).back()]=d[i];
mp[d[i]].pop_back();
}
// replacing the d[i] at index that is going to get changed at last
else{
a[ind]=d[i];
}
}
// checking for whethere the a has been transformed to b
int c=0;
loop(i,0,n){
if( a[i] != b[i] ){
c=1;
break;
}
}
if( !c)cout<<yes;
else cout<<no;

} return 0; } ~~~~~

#### History

Revisions

Rev. Lang. By When Δ Comment