A. Road To Zero
Code
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fi first
#define se second
#define ll long long
#define pb push_back
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef double db;
const ll mod=1e9+7;
ll powmod(ll a,ll b,ll p){ll res=1;a%=p;while(b){if(b&1) res=res*a%p;a=a*a%p;b>>=1;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
int _;
int main(){
for(scanf("%d",&_);_;_--){
ll x,y,a,b;
cin>>x>>y>>a>>b;
if(a+a<=b)
cout<<(x+y)*a<<endl;
else
cout<<min(x,y)*b+abs(y-x)*a<<endl;
}
}
B. Binary Period
Code
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fi first
#define se second
#define ll long long
#define pb push_back
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef double db;
const ll mod=1e9+7;
ll powmod(ll a,ll b,ll p){ll res=1;a%=p;while(b){if(b&1) res=res*a%p;a=a*a%p;b>>=1;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
int _;
int main(){
for(scanf("%d",&_);_;_--){
string t;
cin>>t;
bool same=1;
int n=t.size();
rep(i,1,n)
if(t[i]!=t[i-1])
same=false;
if(same)
cout<<t<<endl;
else {
rep(i,0,n)
cout<<"01";
puts("");
}
}
}
C. Yet Another Counting Problem
Code
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fi first
#define se second
#define ll long long
#define pb push_back
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef double db;
const ll mod=1e9+7;
ll powmod(ll a,ll b,ll p){ll res=1;a%=p;while(b){if(b&1) res=res*a%p;a=a*a%p;b>>=1;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int _;
int main(){
for(scanf("%d",&_);_;_--){
ll a,b,q;
scanf("%lld%lld%lld",&a,&b,&q);
int d=lcm(a,b);
vi rec(d);
vi sum(d);
fill(sum.begin(),sum.end(),0);
rep(i,1,d) {
if((i%a)%b != (i%b)%a) rec[i]=1;
}
rep(i,1,d) sum[i]+=sum[i-1]+rec[i];
while(q--){
ll l,r;
scanf("%lld%lld",&l,&r);
l = (l-1)/d * sum[d-1] +sum[(l-1)%d];
r= r/d *sum[d-1] +sum[r%d];
printf("%lld ", r-l);
}
}
}
D. Multiple Testcases
Code
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fi first
#define se second
#define ll long long
#define pb push_back
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef double db;
const ll mod=1e9+7;
ll powmod(ll a,ll b,ll p){ll res=1;a%=p;while(b){if(b&1) res=res*a%p;a=a*a%p;b>>=1;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
int n,k;
bool cmp(int a, int b){return a>b;}
int main(){
scanf("%d%d",&n,&k);
vi m(n);
vi c(k+1);
rep(i,0,n) scanf("%d", &m[i]);
rep(i,1,k+1) scanf("%d",&c[i]);
sort(m.begin(),m.end());
reverse(m.begin(),m.end());
int ans=0;
int g=0;
per(i,1,k+1){
while(g<n && m[g] == i) ++g;
ans=max(ans,(g+c[i]-1)/c[i]);
}
vector<vi> res(ans);
printf("%d
",ans);
rep(i,0,n) res[i%ans].pb(m[i]);
rep(i,0,res.size()){
printf("%d ",res[i].size());
for(auto it : res[i])
printf("%d ",it);
puts("");
}
}
E. Placing Rooks
第二类斯特林数,待补