feat: Add solutions for Codeforces problems 1991 A, B, and C
This commit is contained in:
parent
a46540ab76
commit
2cbe3ba219
48
Codes/1991 A - Maximize the Last Element/1991A.cpp
Normal file
48
Codes/1991 A - Maximize the Last Element/1991A.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "Assets/debug.h"
|
||||
#endif
|
||||
#define int long long
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define ins insert
|
||||
#define pb push_back
|
||||
#define ppb pop_back
|
||||
#define sz(x) (int)(x).size()
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define rep(i,a,b) for(int i=a; i<b; ++i)
|
||||
#define rrep(i,a,b) for(int i=a; i>=b; --i)
|
||||
#define yn(f) f? cout<<"YES\n":cout<<"NO\n"
|
||||
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
|
||||
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;
|
||||
cin>>n;
|
||||
int mx=0;
|
||||
for(int i=1; i<=n; ++i)
|
||||
{
|
||||
int x;
|
||||
cin>>x;
|
||||
if(i&1) mx=max(mx,x);
|
||||
}
|
||||
cout<<mx<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
58
Codes/1991 B - AND Reconstruction/1991B.cpp
Normal file
58
Codes/1991 B - AND Reconstruction/1991B.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "Assets/debug.h"
|
||||
#endif
|
||||
#define int long long
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define ins insert
|
||||
#define pb push_back
|
||||
#define ppb pop_back
|
||||
#define sz(x) (int)(x).size()
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define rep(i,a,b) for(int i=a; i<b; ++i)
|
||||
#define rrep(i,a,b) for(int i=a; i>=b; --i)
|
||||
#define yn(f) f? cout<<"YES\n":cout<<"NO\n"
|
||||
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
|
||||
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;
|
||||
cin >> n;
|
||||
vector<int> b(n-1);
|
||||
vector<int> a(n);
|
||||
rep(i, 0, n-1) cin >> b[i];
|
||||
a[0] = b[0];
|
||||
rep(i, 1, n-1) a[i] = b[i-1] | b[i];
|
||||
a[n-1] = b[n-2];
|
||||
rep(i,1,n)
|
||||
{
|
||||
int x=a[i]&a[i-1];
|
||||
int y=b[i-1];
|
||||
if(x!=y)
|
||||
{
|
||||
cout<<-1<<endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
rep(i, 0, n) cout << a[i] << " ";
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
61
Codes/1991 C - Absolute Zero/1991C.cpp
Normal file
61
Codes/1991 C - Absolute Zero/1991C.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "Assets/debug.h"
|
||||
#endif
|
||||
#define int long long
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define ins insert
|
||||
#define pb push_back
|
||||
#define ppb pop_back
|
||||
#define sz(x) (int)(x).size()
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define rep(i,a,b) for(int i=a; i<b; ++i)
|
||||
#define rrep(i,a,b) for(int i=a; i>=b; --i)
|
||||
#define yn(f) f? cout<<"YES\n":cout<<"NO\n"
|
||||
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
|
||||
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;
|
||||
cin>>n;
|
||||
bool even=0,odd=0;
|
||||
rep(i,0,n)
|
||||
{
|
||||
int x;
|
||||
cin>>x;
|
||||
if(x&1)
|
||||
odd=1;
|
||||
else
|
||||
even=1;
|
||||
}
|
||||
if(even && odd)
|
||||
{
|
||||
cout<<-1<<endl;
|
||||
return;
|
||||
}
|
||||
vector<int>ans;
|
||||
rrep(i,29,0) ans.pb(1<<i);
|
||||
if(even) ans.pb(1);
|
||||
cout<<ans.size()<<endl;
|
||||
for(auto x:ans) cout<<x<<" ";
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
17
Readme.md
17
Readme.md
@ -367,13 +367,16 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 355 | 1989 A | Catch the Coin | [Question](https://codeforces.com/problemset/problem/1989/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1989%20A%20-%20Catch%20the%20Coin)
|
||||
| 356 | 1989 B | Substring and Subsequence | [Question](https://codeforces.com/problemset/problem/1989/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1989%20B%20-%20Substring%20and%20Subsequence)
|
||||
| 357 | 1989 C | Two Movies | [Question](https://codeforces.com/problemset/problem/1989/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1989%20C%20-%20Two%20Movies)
|
||||
| 358 | 1992 A | Only Pluses | [Question](https://codeforces.com/problemset/problem/1992/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20A%20-%20Only%20Pluses)
|
||||
| 359 | 1992 B | Angry Monk | [Question](https://codeforces.com/problemset/problem/1992/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20B%20-%20Angry%20Monk)
|
||||
| 360 | 1992 C | Gorilla and Permutation | [Question](https://codeforces.com/problemset/problem/1992/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20C%20-%20Gorilla%20and%20Permutation)
|
||||
| 361 | 1996 A | Legs | [Question](https://codeforces.com/problemset/problem/1996/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20A%20-%20Legs)
|
||||
| 362 | 1996 B | Scale | [Question](https://codeforces.com/problemset/problem/1996/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20B%20-%20Scale)
|
||||
| 363 | 1996 C | Sort | [Question](https://codeforces.com/problemset/problem/1996/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20C%20-%20Sort)
|
||||
| 364 | 1996 D | Fun | [Question](https://codeforces.com/problemset/problem/1996/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20D%20-%20Fun)
|
||||
| 358 | 1991 A | Maximize the Last Element | [Question](https://codeforces.com/problemset/problem/1991/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1991%20A%20-%20Maximize%20the%20Last%20Element)
|
||||
| 359 | 1991 B | AND Reconstruction | [Question](https://codeforces.com/problemset/problem/1991/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1991%20B%20-%20AND%20Reconstruction)
|
||||
| 360 | 1991 C | Absolute Zero | [Question](https://codeforces.com/problemset/problem/1991/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1991%20C%20-%20Absolute%20Zero)
|
||||
| 361 | 1992 A | Only Pluses | [Question](https://codeforces.com/problemset/problem/1992/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20A%20-%20Only%20Pluses)
|
||||
| 362 | 1992 B | Angry Monk | [Question](https://codeforces.com/problemset/problem/1992/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20B%20-%20Angry%20Monk)
|
||||
| 363 | 1992 C | Gorilla and Permutation | [Question](https://codeforces.com/problemset/problem/1992/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20C%20-%20Gorilla%20and%20Permutation)
|
||||
| 364 | 1996 A | Legs | [Question](https://codeforces.com/problemset/problem/1996/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20A%20-%20Legs)
|
||||
| 365 | 1996 B | Scale | [Question](https://codeforces.com/problemset/problem/1996/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20B%20-%20Scale)
|
||||
| 366 | 1996 C | Sort | [Question](https://codeforces.com/problemset/problem/1996/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20C%20-%20Sort)
|
||||
| 367 | 1996 D | Fun | [Question](https://codeforces.com/problemset/problem/1996/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20D%20-%20Fun)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user