A. Marathon
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int res=0;
if(b>a)res++;
if(c>a)res++;
if(d>a)res++;
cout<<res<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
B. All Distinct
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=51;
int a[N];
void solve()
{
cin>>n;
map<int,int>mp;
for(int i=1;i<=n;i++)cin>>a[i],mp[a[i]]++;
int res=0;
for(auto x:mp)
{
if(x.y>=2)res+=x.y-1;
}
if(res%2)cout<<mp.size()-1<<endl;
else cout<<mp.size()<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
C. Where’s the Bishop?
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=10;
char g[N][N];
void solve()
{
n=8;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>g[i][j];
for(int i=2;i<n;i++)
for(int j=2;j<n;j++)
if(g[i][j]=='#')
{
if(g[i-1][j-1]=='#'&&g[i-1][j+1]=='#'&&g[i+1][j-1]=='#'&&g[i+1][j+1]=='#')
{
cout<<i<<' '<<j<<endl;
return;
}
}
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
D. The Clock
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
int x;
char c;
int h,m;
cin>>h>>c>>m>>x;
map<int,int>mp;
int res=0;
int now=h*60+m;
while(1)
{
if(mp.count(now))break;
else mp[now]++;
int a=now/60,b=now-a*60;
int r=0;
int bs=b;
for(int i=0;i<2;i++)
{
r=r*10+bs%10;
bs/=10;
}
if(a==r)res++;
now+=x;
if(now>=1440)now-=1440;
}
cout<<res<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
E. Binary Deque
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,sum;
const int N=2e5+10;
int s[N];
int a[N];
int l,r;
int start;
bool check(int x)
{
return s[x]-s[start-1]<=sum;
}
void solve()
{
cin>>n>>sum;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
int cnt=ll_INF;
if(s[n]<sum)
{
cout<<-1<<endl;
return;
}
if(s[n]==sum)
{
cout<<0<<endl;
return;
}
for(int i=1;i<=n;i++)
{
l=i;
start=l;
r=n;
while(l<r)
{
int mid=l+r+1>>1;
if(check(mid))l=mid;
else r=mid-1;
}
int len=l-i+1;
cnt=min(cnt,n-len);
}
cout<<cnt<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
F. 3SUM
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,sum;
int a[10];
void solve()
{
cin>>n;
memset(a,0,sizeof a);
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
a[x%10]++;
}
int res=0;
for(int i=0;i<=9;i++)
{
for(int j=0;j<=9;j++)
{
for(int k=0;k<=9;k++)
{
if(i==j&&a[i]<2)continue;
if(j==k&&a[j]<2)continue;
if(i==k&&a[i]<3)continue;
if(i==j&&j==k&&a[i]<3)continue;
if((i+j+k)%10==3&&a[i]&&a[j]&&a[k])res++;
}
}
}
if(res)puts("YES");
else puts("NO");
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
G. 2^Sort
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=2e5+10;
int a[N];
bool st[N];
int s[N];
void solve()
{
memset(st,0,sizeof st);
memset(s,0,sizeof s);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++)
if(a[i]>=a[i+1]*2)st[i+1]=true;
for(int i=1;i<=n;i++)s[i]=s[i-1]+st[i];
int res=0;
for(int i=1;i+k<=n;i++)
{
int r=i+k;
if(s[r]-s[i-1]==0)res++;
if(s[r]-s[i-1]==1&&s[i]-s[i-1]==1)res++;
}
cout<<res<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
H. Gambling
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=200010;
int f[N],l[N];
void solve()
{
cin>>n;
vector<int>v;
map<int,int>mp;
int res=0;
int ans=0,rr=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
f[i]=1,l[i]=i;
if(mp.count(x))
{
if(f[i]<f[mp[x]]+1-(i-1-mp[x]))
{
f[i]=f[mp[x]]+1-(i-1-mp[x]);
l[i]=l[mp[x]];
}
}
mp[x]=i;
if(res<f[i])
{
res=f[i];
rr=i;
ans=x;
}
}
cout<<ans<<' '<<l[rr]<<' '<<rr<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}