D - Doin’ Time
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
ll a[305];
ll dp[305][305];
ll mp[305][305];
ll m=1000003;
void solve(){
ll n;
cin>>n;
for(ll i=1;i<=n;i++) cin>>a[i];
for(ll i=1;i<=n;i++){
dp[i][i-1]=1;
for(ll j=i;j<=n;j++){
dp[i][j]=(dp[i][j-1]*a[j])%m;
}
}
for(ll r=1;r<=n;r++){
for(ll l=r+1;l>=1;l--){
for(ll k=l;k<r;k++){
ll w=dp[l][k]-dp[k+1][r];
w*=w;
mp[l][r]=max(mp[l][r],mp[l][k]+mp[k+1][r]+w);
//cout<<l<<" "<<r<<" "<<mp[l][r]<<endl;
}
}
}
cout<<mp[1][n]<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
F - Function
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e7 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
//int euler[N];
ll quick_pow(ll a,ll i){
if(!i) return 1;
ll t=quick_pow(a,i>>1);
t*=t;
if(i&1) t*=a;
return t;
}
// void geteuler(){
// euler[1]=1;
// for(int i=2;i<=1e7;i++){
// if(!euler[i]){
// for(int j=i;j<=1e7;j+=i){
// if(!euler[j]) euler[j]=j;
// euler[j]=euler[j]/i*(i-1);
// }
// }
// }
// }
ll pla[N];
vector<ll>pri;
void judge(){
for(int i=2;i<=1e7;i++){
if(!pla[i]){
pla[i]=i;
pri.emplace_back(i);
for(int j=i;j<=1e7;j+=i){
if(!pla[j]) pla[j]=i;
}
}
}
}
ll f(ll x){
ll tot=0;
ll res;
ll pos;
while(x>1){
pos=pla[x];
//cout<<pos<<endl;
while(x&&!(x%pos)){
tot++;
x/=pos;
}
break;
}
tot/=2;
res=x*quick_pow(pos,tot);
return res;
}
void solve(){
judge();
ll n;
cin>>n;
ll res=0;
for(int i=1;i<=n;i++) res+=f(i);//,cout<<f(i)<<endl;
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
H - Hack DSU!
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_bakc
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
void solve(){
int n,t;
cin>>n>>t;
cout<<n<<" "<<1<<endl;
for(int i=n-1;i>1;i--) cout<<i<<" "<<i-1<<endl;
cout<<1<<" "<<n<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
J - JOJO’s Factory
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int a[N],b[N];
int aa,bb;
void solve(){
int n,m;
cin>>n>>m;
aa=bb=n;
while(m--){
int u,v;
cin>>u>>v;
a[u]++;
b[v]++;
if(a[u]>=n) aa--;
if(b[v]>=n) bb--;
}
cout<<min(aa,bb)<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
K - Keep Eating
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
void solve(){
ll n,k;
cin>>n>>k;
ll sum=0;
for(ll i=1;i<=n;i++){
ll x;
cin>>x;
sum+=x;
}
if(sum<k) cout<<"0"<<endl;
else cout<<sum-k+(k/2)<<endl;
//cout<<sum-k<<" "<<k/2<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}