Link to contest : SPC Round #003
A. SPC Gifts
Problem Author : sapta0506
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
const int32_t N = 1e6+1;
void solve()
{
int a,b,k; cin >> a >> b >> k;
cout << min(a,b)/k << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t; cin >> t;
while (t--)
solve();
return 0;
}
B. Void Knight
Problem Author : iowiz
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
int max_length=0;
int number_of_powerups=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>max_length)
{
number_of_powerups++;
max_length = a[i];
}
}
cout<<number_of_powerups<<endl;
}
}
C. Treasure Hunt
Problem Author : Mantra7
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int ans=0;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
int x=a[i]%k;
if(x) ans+=k-x;
}
cout<<ans<<"\n";
}
}
D. Bee's Path
Problem Author : sAshquAsh
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int f[1000001];
void solve()
{
int n;
cin>>n;
cout<<(f[n-1])%mod<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
f[0]=1;f[1]=2;
for(int i=2;i<=1e6;i++) f[i]=(f[i-1] + f[i-2])%mod;
int t; cin >> t;
while(t--) solve();
return 0;
}
E. Switchboard Puzzle
Problem Author : Cheata
Tutorial
Tutorial is loading...
Solution Code
#include <bits/stdc++.h>
#define ll long long
int i;
using namespace std;
const ll mod = 1e9 + 7;
void solv()
{
int n;
cin>>n;
ll a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
ll time=0;
for(i=0;i<n;i++)
{
time=(time+(i+1)*a[i] - i)%mod;
}
cout<<time%mod<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int testcases=1; cin>>testcases;
while(testcases--) solv();
}
F. Rickrolled...
Problem Author : craigfederighi
Tutorial
Tutorial is loading...
Solution Code
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(a) (int)a.size()
#define mod 1000000007
void solv()
{
string str;
cin>>str;
int freq[26]={0};
int n=str.length();
for(int i=0;i<n;i++)
{
freq[str[i]-97]++;
}
ll ans=n;
ans*=(n-1);
ans/=2;
for(int i=0;i<26;i++)
{
ans-=(freq[i]*(freq[i]-1))/2;
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll test_cases=1;
cin>>test_cases;
for(ll loop_var=1;loop_var<=test_cases;loop_var++)
{
solv();
}
return 0;
}
G. Boooring Maths
Problem Author : KDVinit
Tutorial
Tutorial is loading...
Solution Code
// K.D. Vinit |,,|
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a, b, c, k;
bool check(int x)
{
int tmp = (x*x*x) + (a*x*x) + (b*x) + c;
if(tmp<=k) return true;
else return false;
}
void solve()
{
cin>>a>>b>>c>>k;
int l=-1, r=1e6;
while(l+1!=r)
{
int mid = (l+r)/2;
if(check(mid)) l=mid;
else r=mid;
}
int ans=l+1;
cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t; cin>>t;
while(t--) solve();
return 0;
}
H. Coin Heist
Problem Author : sapta0506
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int32_t N = 1e6+1;
void solve()
{
int n,m,k; cin >> n >> m >> k;
if(m==1){
int is_prime=1;
for(int i=2; i*i<=n; i++)
{
if(n%i==0) is_prime=0;
}
if(is_prime) cout<<"UNSAFE"<<endl;
else cout<<"SAFE"<<endl;
return;
}
if(n < 2*k + 4*(m-k)){
cout << "UNSAFE\n";
return;
}
if(k>=1){
cout << "SAFE\n";
return;
}
n -= 4*m;
if(n%2==0) cout << "SAFE\n";
else{
if(n==1 || n==3) cout << "UNSAFE\n";
else cout << "SAFE\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t; cin >> t;
while (t--)
solve();
return 0;
}
I. Who makes the best problems?
Problem Author : Mantra7
Tutorial
Tutorial is loading...
Solution Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int win[10000001]={0};
for(int i=2;i<10000001;i++)
{
if(win[i]==0)
{
for(int j=2;j<=i;j++)
{
if(i*j>10000000) break;
win[i*j]=1;
}
}
}
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string s[2]={"Aditya","Saptarshi"};
cout<<s[win[n]]<<"\n";
}
}
J. Can Tahir Solve It Before Kira Again?
Problem Author : KDVinit,anushka039
Tutorial
Tutorial is loading...
Solution Code
/*
K.D. Vinit |,,|
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int Fact_Length = 5e5 + 1; //Max length
//Takes a&b as input and Returns : The power (a,b), (a^b)%mod
int Power(int base, int expo)
{
int $result=1; base%=mod;
while(expo) { if(expo%2==1) $result=($result*base)%mod; base=(base*base)%mod; expo/=2; }
return $result;
}
// It give the modulo inverse of a, (1/a)%mod
int Mod_Inv(int $a) { return Power($a,mod-2); }
int Factorial[Fact_Length];
// It make the above Factorial[i] = i! array
int Make_Factorial()
{
Factorial[0]=1;
for(int i=1;i<Fact_Length;i++) { Factorial[i]=(i*Factorial[i-1])%mod; } return 0;
}
int Implement_Make_Factorial=Make_Factorial(); //To Implement Make_Factorial
// Takes n&r as input and Returns : nCr%mod
int nCr(int $n,int $r)
{
if($n<$r || $n<0 || $r<0) return 0;
//if($n>Fact_Length) { cout<<"Error"<<endl; return; }
int $ans=(Factorial[$n]*Mod_Inv(Factorial[$r]))%mod;
$ans=($ans*Mod_Inv(Factorial[$n-$r]))%mod;
return $ans;
}
void solve()
{
int n, k;
cin>>n>>k;
n-=2;
int N = n+2*k;
int ct = nCr(N, k); //Total number of ways
int ca = nCr(N, k-1); //Ways that will get before 1
int cb = nCr(N, k-1); //Ways that will reach N earlier
int cc1 = nCr(N, k-2); //Ways that will have both the errors
int cc2 = nCr(N, k-2-n); //Ways that will have both the errors
int cc = cc1 + cc2;
int ans = ct-ca-cb+cc;
ans%=mod;
if(ans<0) ans+=mod;
cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t; cin>>t;
while(t--) solve();
return 0;
}