AtCoder

ARC067 C -Factors of Factorial

問題 atcoder.jp コード int N; map<int,int> prime_factor(int64_t n) { map<int,int> ret; for(int64_t i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } int main(){ //cout.precision(10); cin.tie(0); ios::sy</int,int></int,int>…

ABC011 C - 123引き算

問題 atcoder.jp コード int N; int a,b,c; int main(){ //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); cin >> N; cin >> a >> b >> c; int dp[310]; memset(dp,110,sizeof(dp)); dp[0] = 0; REP(i,N){ if(i != a && i != b && i != c){ …

ABC138 D - Ki

問題 atcoder.jp コード vector<vector<int>> G; vector<int> score; vector<bool> seen; void dfs(int v,int point){ if(!seen[v]){ seen[v] = true; score[v] += point; for(int next_v:G[v]){ dfs(next_v,score[v]); } } } int main(){ //cout.precision(10); cin.tie(0); ios::s</bool></int></vector<int>…

ABC079 D - Wall

問題 atcoder.jp コード int main(){ //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); int H,W; cin >> H >> W; int G[10][10]; rep(i,10)rep(j,10) cin >> G[i][j]; int V = 10; //ワーシャルフロイド法 for (int k = 0; k < V; k++) { fo…

ABC026 C - 高橋君の給料

問題 atcoder.jp コード vector<vector<int>> b; int solve(int x){ int cost; vector<int> y; if(sz(b[x])){ for(int i: b[x]){ y.PB(solve(i)); } auto itr_max = max_element(ALL(y)); auto itr_min = min_element(ALL(y)); return cost = *itr_max + *itr_min + 1; }else{</int></vector<int>…

ABC027 B - 島と橋

問題 atcoder.jp コード int main(){ //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> a(N); rep(i,N) cin >> a[i]; int sum = accumulate(ALL(a),0); if(sum % N){ cout << -1 << endl; return 0; } int ave = su</int>…

ABC084 C - Spetial Trains

問題 atcoder.jp コード #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> VLL; typedef vector<pair<int,int>> VP; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define rep(i,n) for(int i=0; i<(in</pair<int,int></long></bits/stdc++.h>…

ABC146D - Coloring Edges on Tree

問題 atcoder.jp コード struct Edge{ int to,index; }; vector<bool> seen; vector<int> parent; vector<int> vert; vector<vector<Edge>> G; void dfs(int v,int p,int num,int index){ vert[index] = num; int tmp = 1; for(auto next_e:G[v]){ if(tmp == num) tmp++; dfs(next_e.to,v,</vector<edge></int></int></bool>…

ARC097C Kth-Substring

問題 atcoder.jp コード int main(){ //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); string s; int K; cin >> s >> K; int N = s.size(); vector<vector<int> > a(26); rep(i,N){ a[s[i]-'a'].PB(i); } vector<string> S,ans; rep(i,26){ if(!a[i].empty()){ </string></vector<int>…

ABC022C Blue Bird

問題 atcoder.jp コード(テンプレは省略) using P = pair<int, int>; struct edge { int to; int cost; }; int V; vector<edge> G[400]; int d[100000]; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P> > que; fill(d, d+V, INF); d[s] = 0; que.push(P(0, s)); while (!qu</p></p,></edge></int,>…

ABC37 D 経路

問題 atcoder.jp コード(テンプレは省略) int H,W; ll a[1010][1010]; ll dp[1010][1010]; void dfs(int x,int y){ if(dp[x][y]) return; dp[x][y] = 1; if(x > 0 && a[x][y] < a[x-1][y]){ dfs(x-1,y); dp[x][y] += dp[x-1][y]; dp[x][y] %= (ll)MOD; } if(…

DDCC予選

問題 atcoder.jp A DDCC Finals コード(テンプレは省略) ll point(ll a){ if(a == 1) return 300000; if(a == 2) return 200000; if(a == 3) return 100000; return 0; } int main(){ ll x,y; cin >> x >> y; cout << point(x) + point(y) + (x*y==1?400000:…

問題 atcoder.jp コード #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> VLL; typedef vector<pair<int,int>> VP; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define MOD (1e9+7) #define rep(i,n</pair<int,int></long></bits/stdc++.h>…

ABC003 C AtCoderプログラミング講座

問題 atcoder.jp コード #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> VLL; typedef vector<pair<int,int>> VP; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define MOD (1e9+7) #define rep(i,n</pair<int,int></long></bits/stdc++.h>…

ABC135 D Digits Parade

問題 atcoder.jp コード #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <queue> #include <iostream> #include <set> #include <map> #include <string> #include <algorithm> #include <stack> #include <sstream> #include <list> using namespace std; #define rep(…</list></sstream></stack></algorithm></string></map></set></iostream></queue></vector></cmath></cstring></cstdlib></cstdio>

ABC145 感想

ABC145 問題 atcoder.jp A r * r B s[i]とs[i+n/2]をi=[0,n/2)で順に調べていく C グラフで考えると、枝の総数は本。各!通りの経路について、1つの経路に使用される枝の本数は本。 よって、経路の総和のが1つの経路に使われていることがわかるから、対称性…

ARC043 A 点数変換

問題 atcoder.jp コード C++ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> VLL; typedef vector<pair<int,int>> VP; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define MOD (1e9+7) #define rep</pair<int,int></long></bits/stdc++.h>…

AGC 018 A

問題 atcoder.jp コード import numpy as np import sys import math from functools import reduce import fractions as fr def gcd(*numbers): return reduce(fr.gcd, numbers) n,k = map(int,input().split()) a = list(map(int,input().split())) c = in…

ABC114 755

問題 atcoder.jp 方針 ABC119 Synthetic Kadomatsuと似ていたので、DFSで実装した。 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> VLL; typedef vector<pair<int,int>> VP; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 99999</pair<int,int></long></bits/stdc++.h>…