added 1980 c &D

This commit is contained in:
ShazidMahsrafi 2024-06-07 00:15:29 +06:00
parent 8c2b5c7b65
commit 10feba451c
3 changed files with 112 additions and 3 deletions

View File

@ -0,0 +1,46 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void solve()
{
int n,m;
cin>>n;
vector<int>a(n),b(n);
for(auto &i:a) cin>>i;
for(auto &i:b) cin>>i;
cin>>m;
vector<int>d(m);
map<int,int>mp;
for(int i=0; i<m; ++i)
{
cin>>d[i];
mp[d[i]]++;
}
bool f=1;
for(int i=0; i<n; ++i)
{
if(a[i]==b[i]) continue;
if(mp[b[i]])
mp[b[i]]--;
else
f=0;
}
if(count(b.begin(),b.end(), d[m-1])==0) f=0;
if(f) cout<<"YES\n";
else cout<<"NO\n";
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,61 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
bool good(vector<int>v, int del)
{
v.erase(v.begin()+del);
int last=gcd(v[0],v[1]);
for(int i=1; i<v.size()-1; ++i)
{
int cur=gcd(v[i],v[i+1]);
if(cur<last)
{
del=i;
return false;
}
last=cur;
}
return true;
}
void solve()
{
int n;
cin>>n;
vector<int>v(n);
for(auto &i:v) cin>>i;
int del=-1;
int last=gcd(v[0],v[1]);
for(int i=1; i<n-1; ++i)
{
int cur=gcd(v[i],v[i+1]);
if(cur<last)
{
del=i;
break;
}
last=cur;
}
if(del==-1)
{
cout<<"YES\n";
return;
}
if(good(v,del-1) || good(v,del) || good(v,del+1)) cout<<"YES\n";
else cout<<"NO\n";
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -331,9 +331,11 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 319 | 1977 A | Little Nikita | [Question](https://codeforces.com/problemset/problem/1977/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1977%20A%20-%20Little%20Nikita)
| 320 | 1980 A | Problem Generator | [Question](https://codeforces.com/problemset/problem/1980/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1980%20A%20-%20Problem%20Generator)
| 321 | 1980 B | Choosing Cubes | [Question](https://codeforces.com/problemset/problem/1980/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1980%20B%20-%20Choosing%20Cubes)
| 322 | 1981 A | Turtle and Piggy Are Playing a Game | [Question](https://codeforces.com/problemset/problem/1981/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20A%20-%20Turtle%20and%20Piggy%20Are%20Playing%20a%20Game)
| 323 | 1981 B | Turtle and an Infinite Sequence | [Question](https://codeforces.com/problemset/problem/1981/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20B%20-%20Turtle%20and%20an%20Infinite%20Sequence)
| 324 | 1981 C | Turtle and an Incomplete Sequence | [Question](https://codeforces.com/problemset/problem/1981/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20C%20-%20Turtle%20and%20an%20Incomplete%20Sequence)
| 322 | 1980 C | Sofia and the Lost Operations | [Question](https://codeforces.com/problemset/problem/1980/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1980%20C%20-%20Sofia%20and%20the%20Lost%20Operations)
| 323 | 1980 D | GCD-sequence | [Question](https://codeforces.com/problemset/problem/1980/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1980%20D%20-%20GCD-sequence)
| 324 | 1981 A | Turtle and Piggy Are Playing a Game | [Question](https://codeforces.com/problemset/problem/1981/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20A%20-%20Turtle%20and%20Piggy%20Are%20Playing%20a%20Game)
| 325 | 1981 B | Turtle and an Infinite Sequence | [Question](https://codeforces.com/problemset/problem/1981/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20B%20-%20Turtle%20and%20an%20Infinite%20Sequence)
| 326 | 1981 C | Turtle and an Incomplete Sequence | [Question](https://codeforces.com/problemset/problem/1981/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20C%20-%20Turtle%20and%20an%20Incomplete%20Sequence)