Added solutions for Codeforces problems 1969A and 1969B
This commit is contained in:
parent
18d2cecec1
commit
8f472939de
42
Codes/1969 A - Two Friends/1969A.cpp
Normal file
42
Codes/1969 A - Two Friends/1969A.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "debug.h"
|
||||
#endif
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define sz(x) (int)(x).size()
|
||||
#define yes cout<<"YES"<<endl
|
||||
#define no cout<<"NO"<<endl
|
||||
#define FAST (ios_base:: sync_with_stdio(false),cin.tie(NULL));
|
||||
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>v(n);
|
||||
for(auto &i:v) cin>>i;
|
||||
for(int i=0; i<n; ++i)
|
||||
{
|
||||
int fnd=i+1;
|
||||
int bst=v[i];
|
||||
if(v[bst-1]==fnd)
|
||||
{
|
||||
cout<<2<<endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cout<<3<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TC = 1;
|
||||
cin >> TC;
|
||||
while (TC--) solve();
|
||||
}
|
39
Codes/1969 B - Shifts and Sorting/1969B.cpp
Normal file
39
Codes/1969 B - Shifts and Sorting/1969B.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define dbg(...)
|
||||
#else
|
||||
#include "debug.h"
|
||||
#endif
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define sz(x) (int)(x).size()
|
||||
#define yes cout<<"YES"<<endl
|
||||
#define no cout<<"NO"<<endl
|
||||
#define FAST (ios_base:: sync_with_stdio(false),cin.tie(NULL));
|
||||
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()
|
||||
{
|
||||
string s;
|
||||
cin>>s;
|
||||
ll ans=0,ct=0;
|
||||
for(auto c:s)
|
||||
{
|
||||
if(c=='1')
|
||||
ct++;
|
||||
else if(c=='0' && ct)
|
||||
ans += ct+1;
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TC = 1;
|
||||
cin >> TC;
|
||||
while (TC--) solve();
|
||||
}
|
@ -306,6 +306,8 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 294 | 1957 A | Stickogon | [Question](https://codeforces.com/problemset/problem/1957/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20A%20-%20Stickogon)
|
||||
| 295 | 1957 B | A BIT of a Construction | [Question](https://codeforces.com/problemset/problem/1957/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20B%20-%20A%20BIT%20of%20a%20Construction)
|
||||
| 296 | 1957 C | How Does the Rook Move | [Question](https://codeforces.com/problemset/problem/1957/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20C%20-%20How%20Does%20the%20Rook%20Move)
|
||||
| 297 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
|
||||
| 298 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user