Add solutions for Codeforces problems 1996 A, B, C, and D
This commit is contained in:
parent
8b854af193
commit
a46540ab76
56
Codes/1996 A - Legs/1996A.cpp
Normal file
56
Codes/1996 A - Legs/1996A.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#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 ans = n / 4;
|
||||||
|
n %= 4;
|
||||||
|
ans += n / 2;
|
||||||
|
cout << ans << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
FAST;
|
||||||
|
int TCS = 1;
|
||||||
|
cin >> TCS;
|
||||||
|
for (int TC = 1; TC <= TCS; ++TC)
|
||||||
|
{
|
||||||
|
// cout<<"Case "<<TC<<": ";
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
65
Codes/1996 B - Scale/1996B.cpp
Normal file
65
Codes/1996 B - Scale/1996B.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#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,k;
|
||||||
|
cin>>n>>k;
|
||||||
|
int v[n][n];
|
||||||
|
vector<vector<int>>ans;
|
||||||
|
for(int i=0; i<n; ++i)
|
||||||
|
{
|
||||||
|
for(int j=0; j<n; ++j)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
cin>>c;
|
||||||
|
v[i][j] = c-'0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=0; i<n; i+=k)
|
||||||
|
{
|
||||||
|
vector<int>temp;
|
||||||
|
for(int j=0; j<n; j+=k)
|
||||||
|
{
|
||||||
|
temp.pb(v[i][j]);
|
||||||
|
}
|
||||||
|
ans.pb(temp);
|
||||||
|
}
|
||||||
|
for(auto &i:ans)
|
||||||
|
{
|
||||||
|
for(auto &e:i) cout<<e;
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
FAST;
|
||||||
|
int TCS = 1;
|
||||||
|
cin >> TCS;
|
||||||
|
for (int TC = 1; TC <= TCS; ++TC)
|
||||||
|
{
|
||||||
|
// cout<<"Case "<<TC<<": ";
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
64
Codes/1996 C - Sort/1996C.cpp
Normal file
64
Codes/1996 C - Sort/1996C.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#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,q;
|
||||||
|
cin>>n>>q;
|
||||||
|
string a,b;
|
||||||
|
cin>>a>>b;
|
||||||
|
vector<int>cnt(26,0);
|
||||||
|
vector<vector<int>>v;
|
||||||
|
v.pb(cnt);
|
||||||
|
for(int i=0; i<n; ++i)
|
||||||
|
{
|
||||||
|
cnt[a[i]-'a']++;
|
||||||
|
cnt[b[i]-'a']--;
|
||||||
|
v.pb(cnt);
|
||||||
|
}
|
||||||
|
dbg(v);
|
||||||
|
while(q--)
|
||||||
|
{
|
||||||
|
int l,r;
|
||||||
|
cin>>l>>r;
|
||||||
|
int op=0;
|
||||||
|
dbg(v[l-1],v[r]);
|
||||||
|
for(int i=0; i<26; ++i)
|
||||||
|
{
|
||||||
|
op += abs(v[l-1][i]-v[r][i]);
|
||||||
|
}
|
||||||
|
cout<<op/2<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
FAST;
|
||||||
|
int TCS = 1;
|
||||||
|
cin >> TCS;
|
||||||
|
for (int TC = 1; TC <= TCS; ++TC)
|
||||||
|
{
|
||||||
|
// cout<<"Case "<<TC<<": ";
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
51
Codes/1996 D - Fun/1996D.cpp
Normal file
51
Codes/1996 D - Fun/1996D.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#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,x;
|
||||||
|
cin>>n>>x;
|
||||||
|
int ct=0;
|
||||||
|
for(int a=1; a<=x; ++a)
|
||||||
|
{
|
||||||
|
int y=min(x-a, n/a);
|
||||||
|
for(int b=1; b<=y; ++b)
|
||||||
|
{
|
||||||
|
int c=min(x-a-b, (n-a*b)/(a+b));
|
||||||
|
ct += max(0ll,c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<ct<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
FAST;
|
||||||
|
int TCS = 1;
|
||||||
|
cin >> TCS;
|
||||||
|
for (int TC = 1; TC <= TCS; ++TC)
|
||||||
|
{
|
||||||
|
// cout<<"Case "<<TC<<": ";
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
@ -370,6 +370,10 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
|||||||
| 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)
|
| 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)
|
| 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)
|
| 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user