G - Physical Music
答案:
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
#define INF 0x3f3f3f3f
const int N = 1e5 + 10;
using namespace std;
vector<int>vp;
int dp[N];
int tot=0;
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vp.clear();
int minn=INF;
for(int i=1;i<=n;i++) cin>>dp[i];
for(int i=n;i>=1;i--){
if(dp[i]>minn){
vp.pb(dp[i]);
}
minn=min(minn,dp[i]);
}
cout<<(int)vp.size()<<endl;
sort(vp.begin(),vp.end(),greater<int>());
for(int i=(int)vp.size()-1;i>=0;i--){
cout<<vp[i]<<endl;
}
}
return 0;
}
I - Stand on Zanzibar
答案:
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
const int N = 2e5 + 10;
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int k;
int p;
int tot=0;
cin>>p;
if(!p){
cout<<tot<<endl;;
break;
}
while(cin>>k){
if(!k) {
cout<<tot<<endl;;
break;
}
else{
if(p*2<k) tot+=k-2*p;
p=k;
}
}
}
return 0;
}
J - The King’s Walk
答案:
#include <memory.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;
const int N = 10100;
#define ll long long
int f[N][N];
const int mod= 5318008;
void fx(int s,int t,int p,int n){
memset(f,0,sizeof(f)
);
f[0][s]=1;
for(int i=1;i<=p;i++){
for(int j=1;j<=n;j++){
f[i][j]=f[i-1][j]%mod;
if(j<n) f[i][j]+=f[i-1][j+1];
f[i][j]%=mod;
if(j>1) f[i][j]+=f[i-1][j-1];
f[i][j]%=mod;
}
}
printf("%d\n",f[p][t]);
}
int main(){
int n,u,x1,x2,y1,y2;
scanf("%d",&u);
while(u--){
scanf("%d %d %d %d %d",&n,&x1,&y1,&x2,&y2);
int p=abs(x1-x2),q=abs(y1-y2);
if(q<p){
fx(y1,y2,p,n);
}
else {
fx(x1,x2,q,n);
}
}
return 0;
}
L - Wipe Your Whiteboards
答案:
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define pb push_back
#define x first
#define y second
#define INF 0x3f3f3f3f
const int N = 1e5 + 10;
const int mod= 5318008;
using namespace std;
ll a,b;
ll r,s,q;
ll extend_gcd(ll a,ll b,ll &x,ll &y){
//if(!a||!b) return -1;
if(!b){
x=1;
y=0;
return a;
}
// ll d=extend_gcd(b,a%b,x,y);
// ll temp=x;
// x=y;
// y=temp-(a/b)*y;
ll d=extend_gcd(b,a%b,y,x);
y-=(a/b)*x;
return d;
}
int main(){
ios::sync_with_stdio(0);
ll t;
cin>>t;
while(t--){
cin>>r>>s>>q;
ll gcd=extend_gcd(r,-s,a,b);
b=-b;
ll A=(q/gcd)*a;
ll B=(q/gcd)*b;
// cout<<A<<" "<<B<<endl;
//ll temp=q/gcd;
ll xx=s/gcd;
ll yy=r/gcd;
while(A>=1&&B>=1){
A+=xx;
B-=yy;
}
// cout<<A<<" "<<B<<endl;
while(A<1||B<1){
A-=xx;
B+=yy;
}
cout<<A<<" "<<B<<endl;
}
return 0;
}