ãªã7,8ãæãã¦ãããã¨ããã¨ãããããªãããã§ãã
1åç®ãããã£ããã£ã³ãã£
4036 < PCK Prelim < Challenges | Aizu Online Judge
C-10ãåºåãã¦ãã ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int c;
cin>>c;
cout<<c-10<<endl;
}
2åç®ãç¥è¼¿(ã¿ãã)ã®æ
ãæ
4037 < PCK Prelim < Challenges | Aizu Online Judge
w/cã®åãä¸ããè¨ç®ãã¦ããããN以ä¸ãã©ããã
a/b
ã®åãä¸ãã¯(a+b-1)/b
ã§è¨ç®ã§ããã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,c,w;
cin>>n>>c>>w;
int x=(w+c-1)/c;
if(x>n)cout<<"No"<<endl;
else{
cout<<"Yes"<<endl;
cout<<x<<endl;
}
}
3åç®ãã©ããã¼ãã³ãã¼
PCK Prelim < Challenges | Aizu Online Judge
åé¡æã®ã¨ããã«æ°ããã ãã§ãã
nã¯æååã¨ãã¦åãåãã¨æ¥½ã§ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int d;
string n;
cin>>d>>n;
int cnt=0;
for(char c:n){
cnt+=(c-'0'==d);
}
cout<<cnt<<endl;
}
4åç®ãéæ³ã®ãã±ãã
4039 < PCK Prelim < Challenges | Aizu Online Judge
ãã®ãããããé£ãããªã£ã¦ãã¾ãã
ãããC,Dãæå°ã®2ã§ã40åãããå©ãã°ãã¹ã±ããã®æ°ã¯10^12
ãè¶
ãã¾ããT<=10^11
ãªã®ã§å³ã®ãã±ãããå·¦ã®ãã±ãããå©ãåæ°ã¯ã大ä½40以ä¸ã¾ã§èããã°è¯ãã
å
¨æ¢ç´¢ããªã¼ãã¼ããã¼ã«æ°ãã¤ãã¾ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll A,B,C,D,T;
cin>>A>>B>>C>>D>>T;
int ans = 1e9;
ll x = A;
rep(a,40){
ll y = B;
rep(b,40){
if(x+y==T) ans = min(ans, a+b);
y*=D;
if(y>T) break;
}
x*=C;
if(x>T) break;
}
if(ans==1e9) cout<<"No"<<endl;
else {
cout<<"Yes"<<endl;
cout<<ans<<endl;
}
}
5åç®ããã¼ã¿ã»ã³ã¿ã¼
404 Error | Aizu Online Judge
èªç±ã«ç§»åã§ããã®ã§æåã®ãã¡ã¤ã«ã®ä½ç½®ã¯èããå¿
è¦ã¯ããã¾ããã大äºãªã®ã¯ãã¡ã¤ã«ã®ç·æ°ã§ãã
ã§ããã ãå¤ãã®ãµã¼ãã¼ãä½ãããã«ã¯ãããããã®ãã¡ã¤ã«ãæã¦ããµã¼ãã¼ã«åªå
çã«æ¼ãä»ããã¹ãã
貪欲æ³
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
vector<int> c(n),a(n);
rep(i,n){
cin>>c[i]>>a[i];
}
int sum = 0;
rep(i,n) sum+=a[i];
sort(c.begin(),c.end(),greater<int>());
int use = 0;
rep(i,n){
if(sum>0){
sum -= c[i];
use++;
}
}
if(n-use>=m) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
6åç®ãæ¹ã®èª¿æ»
Aizu Online Judge
.
ã®é£çµæåã®åæ°ãæ°ããåé¡ã§ãã
å¨ãã«é£æ¥ãã¦ãã.
ã®éåãã«ã¦ã³ããã¦ã¯ãããªãã®ã§ãäºãåãé¤ãã¦ããã¾ãã
unionfindã§ãè¯ãã§ãããæ¬çªã§ã¯ã©ã¤ãã©ãªãºãï½ã§ããªãã®ã§dfsã§ããã¨æ¥½ã§ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h,w;
cin>>h>>w;
vector<string> s(h);
rep(i,h) cin>>s[i];
vector<vector<int>> used(h,vector<int>(w,0));
auto dfs = [&](auto dfs, int y, int x) -> void {
if(y<0 || h<=y || x<0 || w<=x) return;
if(s[y][x]=='#') return;
if(used[y][x]) return;
used[y][x]=1;
vector<int> dd = {0,1,0,-1,0};
rep(i,4){
dfs(dfs, y+dd[i], x+dd[i+1]);
}
};
rep(i,h){
dfs(dfs, i, 0);
dfs(dfs, i, w-1);
}
rep(j,w){
dfs(dfs, 0, j);
dfs(dfs, h-1, j);
}
int cnt = 0;
rep(i,h){
rep(j,w){
if(s[i][j]=='#') continue;
if(used[i][j]) continue;
dfs(dfs, i, j);
cnt++;
}
}
cout<<cnt<<endl;
}
9åç®ãå£ã®ãªãã©ã¼ã
404 Error | Aizu Online Judge
ãé£ãåãåã®é«ããåããã¯èãã«ããã
å³ãæ¸ãã¦ã¿ãã¨ããããããã¹ã¦ã®iã«ã¤ãã¦h[i]-d[i]
ã®å¤ãä¸è´ããããã¨ã¨åãã
ãå·®ã®ç·åãæå°åããã¨ãã¯ä¸å¤®å¤ã使ããã¨ããå
¸åãããã
C - Linear Approximation
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vector<ll> h(n),d(n);
rep(i,n)cin>>h[i];
rep(i,n)cin>>d[i];
vector<ll> sa(n);
rep(i,n) sa[i] = h[i]-d[i];
sort(sa.begin(),sa.end());
ll md = sa[n/2];
ll cnt = 0;
rep(i,n) cnt += abs(sa[i]-md);
cout<<cnt<<endl;
}
10åç®ãå®å®æ¦è¦ã¤ã
ã¢
404 Error | Aizu Online Judge
åã¯ã¨ãªã®å
¥åããã£ã¡ããããã§ãããåæä½ã®æ大ããèæ
®ããªãã¦è¯ãã§ãã
ç´æçã«ã¯
dp[i][j]
içªç®ã®ã¯ã¨ãªã¾ã§ã¿ã¦ãç¾å¨ã®ãã³ãã®å¼·ããjã®ã¨ãã®ã¹ã³ã¢ã®æ大å¤
ã¨ããdpãããããã§ããããã³ãã®å¼·ããè¶
大ããã®ã§éã«åãã¾ããã
N<=2000
ã§ãããã¨ã«æ³¨ç®ãã¾ãã
ã¯ã¨ãª1(ãã³ãå¢å¼·)ã¯ã以éã¯ã¨ãª2ãè¡ãåæ°ãåããã°å
¨ä½ã®ã¹ã³ã¢ã«å½±é¿ããéãæ±ã¾ãã®ã§ãã®æã«å³å ç®ããã°ãç¾å¨ã®ãã³ãã®å¼·ããdpã«æãããªãã¦è¯ãã
dp[i][j]=
iåç®ã®ã¯ã¨ãªã¾ã§è¦ã¦ã以éã«ã¯ã¨ãª2ãjåè¡ãã¨æ±ºããã¨ãã®ã¹ã³ã¢ã®æ大å¤
çãã¯dp[N][0]
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<vector<ll>> dp(N+1,vector<ll>(N+1,-1e18));
rep(i,N+1)dp[0][i] = 0;
rep(i,N){
int L;
cin>>L;
int l1 = 0;
int l2 = 0;
rep(j,L){
int t,a;
cin>>t>>a;
if(t==1) l1 = max(l1, a);
else l2 = max(l2, a);
}
rep(j,N+1){
if(l1>0 && j>0) dp[i+1][j-1] = max(dp[i+1][j-1], dp[i][j]+l1);
if(l2>0) dp[i+1][j] = max(dp[i+1][j], dp[i][j]+l2*j);
}
}
cout<<dp[N][0]<<endl;
}
11åç®ããã¤ãªã¼ããã·ã§ã³
Aizu Online Judge
æå®ãããé ã§é¨å±ãé çªã«è¨ªãã¦ãããæµã®é¨å±ã«è¨ªããåæ°ãæå°åããããã§ã®ãé¨å±ã®ç§»ååæ°ãæå°å¤ãæ±ãã¦ãã ããã
åå°é¬¼ã®å ´æã¸ã®ç§»åã«ã¤ãã¦ãå§ç¹ã¨çµç¹ã¯æ±ºã¾ã£ã¦ããã®ã§ãç¬ç«ã«èãã¦æå¾ã«è¶³ãåãããã°è¯ãã§ãã
å鬼ã®æ°ãè¶
å¤ãã¦ãé¨å±ã®æ°ã¯300ã¨å°ããã
ã¯ã¼ã·ã£ã«ããã¤ãã§ãã
ãã ãæ®éã®ã¯ã¼ã·ã£ã«ããã¤ãã¨ã¯å°ãã ãéãã¨ããããã£ã¦ã
- 辺ã§ã¯ãªãé ç¹ã«éã¿ãã¤ãã¦ããã
- ããã¯ãã®é ç¹ã¸åãã£ã¦ãã辺ã«éã¿ãããã¨èãã¦è¯ãã§ãã
- æå°åãããå¤ã2ã¤ããã
- æ®éã«pairã§æã¦ã°ããã§ãã
- æ¯ã®é¨å±ãæå°åããããã§ç§»ååæ°ãæå°åãããã®ã§ã
pair<æ¯é¨å±è¨ªæ°, 移ååæ°>
ã®é ã§æããã
- ãããã¯ãæ¯é¨å±ã¸è¨ªããã¨1e9ããã«ãã£ã移åããã¨1ããã«ãã£ã¨ãã¦ãmod1e9ãåºåãã¦ãè¯ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<vector<ll>> G(N,vector<ll>(N,1e18));
rep(i,N) G[i][i]=0;
rep(i,M){
int u,v;
cin>>u>>v;
u--;v--;
G[u][v]=1;
G[v][u]=1;
}
int K;
cin>>K;
vector<int> a(K);
rep(i,K) cin>>a[i],a[i]--;
int Q;
cin>>Q;
rep(i,Q){
int b;
cin>>b;
b--;
rep(j,N){
G[j][b]+=1e9;
}
}
rep(k,N){
rep(i,N){
rep(j,N){
G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
}
}
}
ll ans = 0;
int mae = 0;
rep(i,K){
ans += G[mae][a[i]];
mae=a[i];
}
cout<<ans%(int)1e9<<endl;
}
12åç®ããã°ã¤ã³ãã¼ãã¹
404 Error | Aizu Online Judge
é
延ã»ã°æ¨ã¨ã¯è¨ã£ã¦ãã¾ãããè¨ç®ãããªãè¤éã
g(l,i) = Ai*Si + Bi*f(l,i)
Ai*Si
ã¯ããã ãã
Bi*f(l,i)
ãé¢åã§ãã
f(l,i)
ã¯ãiããåã«1ãä½åé£ç¶ãã¦ããã
ãããæ´æ°ããã«ã¯ã»ã°æ¨ã«ã
- ãã®åºéã®å·¦ç«¯ããä½å1ãé£ç¶ãã¦ãã
- ãã®åºéã®å³ç«¯ããä½å1ãé£ç¶ãã¦ãã
ãæãããã°ããã§ãã
説æé£ããã®ã§è©³ããã¯ã³ã¼ãå
ã®ã³ã¡ã³ãã«æ¸ãã¾ãã
å転ã¯ã¨ãªã§0ã¨1ãå
¥ãæ¿ããå ´åãããã®ã§ãä¸è¨ã®0ãã¼ã¸ã§ã³ãä¿æãã¦ããã¾ãã
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
#include<atcoder/lazysegtree>
using namespace atcoder;
vector<ll> bsum;
struct S{
ll A;
ll AS;
ll Bf1;
ll Bf0;
ll l1;
ll r1;
ll l0;
ll r0;
ll sz;
ll i;
};
S op(S a, S b){
S s;
s.A = a.A+b.A;
s.AS = a.AS+b.AS;
s.l1 = a.l1;
if(a.l1==a.sz){
s.l1 += b.l1;
}
s.l0 = a.l0;
if(a.l0==a.sz){
s.l0 += b.l0;
}
s.r1 = b.r1;
if(b.r1==b.sz){
s.r1 += a.r1;
}
s.r0 = b.r0;
if(b.r0==b.sz){
s.r0 += a.r0;
}
s.Bf1 = a.Bf1+b.Bf1;
s.Bf1 += (bsum[b.i+b.l1]-bsum[b.i])*a.r1;
s.Bf0 = a.Bf0+b.Bf0;
s.Bf0 += (bsum[b.i+b.l0]-bsum[b.i])*a.r0;
s.i = a.i;
s.sz = a.sz+b.sz;
return s;
}
S e(){
return S{0,0,0,0,0,0,0,0,0,0};
}
using F = ll;
S mapping(F f, S a){
S s=a;
if(f==1){
s.AS = a.A-a.AS;
swap(s.Bf0,s.Bf1);
swap(s.l0,s.l1);
swap(s.r0,s.r1);
}
return s;
}
F composition(F f, F g){
return (f+g)%2;
}
F id(){
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin>>n>>q;
vector<ll> a(n),b(n),s(n);
rep(i,n)cin>>a[i];
rep(i,n)cin>>b[i];
rep(i,n)cin>>s[i];
bsum.assign(n+1,0);
rep(i,n) bsum[i+1] = bsum[i]+b[i];
vector<S> init(n);
rep(i,n){
init[i] = S{a[i],a[i]*s[i],b[i]*s[i],b[i]*(1-s[i]),s[i],s[i],1-s[i],1-s[i],1,i};
}
lazy_segtree<S,op,e,F,mapping,composition,id> seg(init);
rep(qi,q){
int c,l,r;
cin>>c>>l>>r;
l--;
if(c==1){
seg.apply(l,r,1);
}
else{
S res = seg.prod(l,r);
cout << res.AS+res.Bf1 << endl;
}
}
}
H - Counting 1's
F - Vacation Query
ããã¨ã解ãããã¨ãªãã¨ç¸å½ãã¤ãã