WA in Div 3 950 C) Sofia and the Lost Operations
Difference between en1 and en2, changed 1,759 character(s)
Problem Link->https://codeforces.com/contest/1980/problem/C↵

Actually trying to generate the sequence.↵

My Code -> ↵
~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
#define max(a,b)( a > b ? a : b )↵
#define loop(i,a,b) for(int i=a;i<b;i++)↵
#define rloop(i,a,b) for(int i=a;i>=b;i--)↵
#define vi vector<int>↵
#define vl vector<ll>↵
#define yes "YES\n"↵
#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;↵
}↵
~~~~~↵

https://codeforces.com/contest/1980/submission/266595387

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English aditya_patil71 2024-06-20 18:50:55 1759
en1 English aditya_patil71 2024-06-20 18:36:35 1954 Initial revision (published)