C. Residential Area
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sf1(a) scanf("%ld",&a)
#define sf2(a,b) scanf("%ld%ld",&a,&b)
#define sf3(a,b,c) scanf("%ld%ld%ld",&a,&b,&c)
#define pf1(a) printf("%ld",a)
#define pf2(a,b) printf("%ld%ld",a,b)
#define pf3(a,b,c) printf("%ld%ld%ld",a,b,c)
int main()
{
long ts,cs=1;
scanf("%ld",&ts);
while(ts--)
{
long n,a=0,b=1,i,j,k,x,cnt=0;
set<long>st;
long s[20][20]= {0};
scanf("%ld",&n);
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin>>s[i][j];
}
}
x=n-4;
if(n<=4)
{
printf("Case %ld: 0\n",cs++);
continue;
}
if(n==10)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
st.insert(s[i][j]);
}
if(st.size()==10)
cnt++;
st.clear();
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
st.insert(s[j][i]);
}
if(st.size()==10)
cnt++;
st.clear();
}
}
for(i=0; i<n-1; i++)
{
for(j=0; j<x; j++)
{
for(k=j; k<j+5; k++)
{
st.insert(s[a][k]);
st.insert(s[b][k]);
}
if(st.size()==10)
{
cnt++;
}
st.clear();
}
a++,b++;
}
st.clear();
a=0,b=1,i=0,k=0,j=0;
for(i=0; i<n-1; i++)
{
for(j=0; j<x; j++)
{
for(k=j; k<j+5; k++)
{
st.insert(s[k][a]);
st.insert(s[k][b]);
}
if(st.size()==10)
{
cnt++;
}
st.clear();
}
a++,b++;
}
printf("Case %ld: %ld\n",cs++,cnt);
}
return 0;
}
D. Connecting To One
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
ll nod,cost;
node(ll a,ll b)
{
nod=a;
cost=b;
}
bool operator<(const node &p)const
{
return p.cost>cost;
}
};
vector<pair<ll,ll> >graph[100001];
ll n,m;
ll u,v,c;
priority_queue<node>q;
ll visited[100001];
void djixtra()
{
visited[1]=10000000000;
q.push(node(1,10000000000));
while(!q.empty())
{
node source=q.top();
q.pop();
ll s=source.nod;
ll nie_asche=source.cost;
for(ll i=0;i<graph[s].size();i++)
{
ll adj=graph[s][i].first;
ll adj_cost=graph[s][i].second;
ll update_hobe=min(adj_cost,nie_asche);
if(visited[adj]<update_hobe)
{
visited[adj]=update_hobe;
q.push(node(adj,update_hobe));
}
}
}
}
vector<ll>ase;
int main()
{
ll tes;
scanf("%lld",&tes);
for(ll cas=1; cas<=tes; cas++)
{
printf("Case %lld:\n",cas);
scanf("%lld%lld",&n,&m);
for(ll i=1; i<=n; i++)
{
graph[i].clear();
visited[i]=LLONG_MIN;
}
ase.clear();
for(ll i=1; i<=m; i++)
{
scanf("%lld%lld%lld",&u,&v,&c);
graph[u].push_back(make_pair(v,c));
graph[v].push_back(make_pair(u,c));
}
djixtra();
ll qu;
for(ll i=1;i<=n;i++)
{
if(visited[i]!=10000000000 && visited[i]!=LLONG_MIN)
{
ase.push_back(visited[i]);
}
}
sort(ase.begin(),ase.end());
// for(ll i=0;i<ase.size();i++)
// {
// cout<<ase[i]<<" ";
// }
scanf("%lld",&qu);
for(ll j=1;j<=qu;j++)
{
scanf("%lld",&u);
ll index=upper_bound(ase.begin(),ase.end(),u-1)-ase.begin();
printf("%lld\n",ase.size()-index);
}
}
return 0;
}
F. Coldplay
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define fr(i,a) for(i=0;i<a;i++)
#define tc(i,t) for(i=1;i<=t;i++)
#define cln(x) memset(x,0,sizeof(x))
#define clr(x) memset(x,-1,sizeof(x))
main()
{
int p,q,y;
while(~scanf("%d%d%d",&p,&q,&y))
{
int x=(y*52)*5*p;
int z=(y*52)*2*q;
printf("%d\n",x+z);
}
return 0;
}
using namespace std;
main()
{
long ts,cs=1;
cin>>ts;
while(ts--)
{
long rs,sum=0,sum1=0,i;
string s,s1;
cin>>s>>s1;
for(i=0;i<s.size();i++)
{
sum=sum*10+s[i]-48;
sum=sum%9;
}
if(sum==0)
sum=9;
for(i=0;i<s1.size();i++)
{
sum1=sum1*10+s1[i]-48;
sum1=sum1%6;
}
if(sum1==0)
sum1=6;
rs=pow(sum,sum1)+.000000000000001;
rs=rs%9;
if(rs==0)
rs=9;
printf("Case %ld: %ld\n",cs++,rs);
}
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sf1(a) scanf("%ld",&a)
#define sf2(a,b) scanf("%ld%ld",&a,&b)
#define sf3(a,b,c) scanf("%ld%ld%ld",&a,&b,&c)
#define pf1(a) printf("%ld",a)
#define pf2(a,b) printf("%ld%ld",a,b)
#define pf3(a,b,c) printf("%ld%ld%ld",a,b,c)
int main()
{
long ts,cs=1;
scanf("%ld",&ts);
while(ts--)
{
long n,a=0,b=1,i,j,k,x,cnt=0;
set<long>st;
long s[20][20]= {0};
scanf("%ld",&n);
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin>>s[i][j];
}
}
x=n-4;
if(n<=4)
{
printf("Case %ld: 0\n",cs++);
continue;
}
if(n==10)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
st.insert(s[i][j]);
}
if(st.size()==10)
cnt++;
st.clear();
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
st.insert(s[j][i]);
}
if(st.size()==10)
cnt++;
st.clear();
}
}
for(i=0; i<n-1; i++)
{
for(j=0; j<x; j++)
{
for(k=j; k<j+5; k++)
{
st.insert(s[a][k]);
st.insert(s[b][k]);
}
if(st.size()==10)
{
cnt++;
}
st.clear();
}
a++,b++;
}
st.clear();
a=0,b=1,i=0,k=0,j=0;
for(i=0; i<n-1; i++)
{
for(j=0; j<x; j++)
{
for(k=j; k<j+5; k++)
{
st.insert(s[k][a]);
st.insert(s[k][b]);
}
if(st.size()==10)
{
cnt++;
}
st.clear();
}
a++,b++;
}
printf("Case %ld: %ld\n",cs++,cnt);
}
return 0;
}
D. Connecting To One
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
ll nod,cost;
node(ll a,ll b)
{
nod=a;
cost=b;
}
bool operator<(const node &p)const
{
return p.cost>cost;
}
};
vector<pair<ll,ll> >graph[100001];
ll n,m;
ll u,v,c;
priority_queue<node>q;
ll visited[100001];
void djixtra()
{
visited[1]=10000000000;
q.push(node(1,10000000000));
while(!q.empty())
{
node source=q.top();
q.pop();
ll s=source.nod;
ll nie_asche=source.cost;
for(ll i=0;i<graph[s].size();i++)
{
ll adj=graph[s][i].first;
ll adj_cost=graph[s][i].second;
ll update_hobe=min(adj_cost,nie_asche);
if(visited[adj]<update_hobe)
{
visited[adj]=update_hobe;
q.push(node(adj,update_hobe));
}
}
}
}
vector<ll>ase;
int main()
{
ll tes;
scanf("%lld",&tes);
for(ll cas=1; cas<=tes; cas++)
{
printf("Case %lld:\n",cas);
scanf("%lld%lld",&n,&m);
for(ll i=1; i<=n; i++)
{
graph[i].clear();
visited[i]=LLONG_MIN;
}
ase.clear();
for(ll i=1; i<=m; i++)
{
scanf("%lld%lld%lld",&u,&v,&c);
graph[u].push_back(make_pair(v,c));
graph[v].push_back(make_pair(u,c));
}
djixtra();
ll qu;
for(ll i=1;i<=n;i++)
{
if(visited[i]!=10000000000 && visited[i]!=LLONG_MIN)
{
ase.push_back(visited[i]);
}
}
sort(ase.begin(),ase.end());
// for(ll i=0;i<ase.size();i++)
// {
// cout<<ase[i]<<" ";
// }
scanf("%lld",&qu);
for(ll j=1;j<=qu;j++)
{
scanf("%lld",&u);
ll index=upper_bound(ase.begin(),ase.end(),u-1)-ase.begin();
printf("%lld\n",ase.size()-index);
}
}
return 0;
}
F. Coldplay
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define fr(i,a) for(i=0;i<a;i++)
#define tc(i,t) for(i=1;i<=t;i++)
#define cln(x) memset(x,0,sizeof(x))
#define clr(x) memset(x,-1,sizeof(x))
main()
{
int p,q,y;
while(~scanf("%d%d%d",&p,&q,&y))
{
int x=(y*52)*5*p;
int z=(y*52)*2*q;
printf("%d\n",x+z);
}
return 0;
}
I.Repeated Digit Sum
#include <bits/stdc++.h>using namespace std;
main()
{
long ts,cs=1;
cin>>ts;
while(ts--)
{
long rs,sum=0,sum1=0,i;
string s,s1;
cin>>s>>s1;
for(i=0;i<s.size();i++)
{
sum=sum*10+s[i]-48;
sum=sum%9;
}
if(sum==0)
sum=9;
for(i=0;i<s1.size();i++)
{
sum1=sum1*10+s1[i]-48;
sum1=sum1%6;
}
if(sum1==0)
sum1=6;
rs=pow(sum,sum1)+.000000000000001;
rs=rs%9;
if(rs==0)
rs=9;
printf("Case %ld: %ld\n",cs++,rs);
}
}