group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_ALDS1_1_B_cpp
Greatest Common Divisor Write a program which finds the greatest common divisor of two natural numbers a and b Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b . Constrants 1 ≤ a , b ≤ 10 9 Hint You can use the following observation: For integers x and y...
[ { "submission_id": "aoj_ALDS1_1_B_10915851", "code_snippet": "#include <iostream>\nusing namespace std;\n\nint main(){\n int x, y; cin >> x >> y;\n int d = 2;\n int gcd = 1;\n\n while(d <= x && d <= y){\n if (x % d == 0 && y % d == 0){\n x = x / d;\n y = y / d;\n ...
aoj_ALDS1_2_D_cpp
Shell Sort Shell Sort is a generalization of Insertion Sort (ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 ...
[ { "submission_id": "aoj_ALDS1_2_D_11015424", "code_snippet": "#include <iostream>\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass my_vector\n{\nprivate: // 隠すもの。外から見えない\n int *a; // 可変長配列\n int n; // 要素数\n int capacity; // 確保する容量\n\npublic: // 公開するもの\n my...
aoj_ALDS1_1_D_cpp
Maximum Profit You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$...
[ { "submission_id": "aoj_ALDS1_1_D_11066075", "code_snippet": "#include<iostream>\nusing namespace std;\nint main ( ) {\n\tint n = 0, min = 0, result = -1000000000, temp = 0;\n\tcin >> n;\n\tcin >> min;\n\tfor (int i = 0; i < n-1; i++) {\n\t\tcin >> temp;\n\t\tif (temp - min > result) {\n\t\t\tresult = temp ...
aoj_ALDS1_1_C_cpp
Prime Numbers A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of N integers and prints the number of prime numbers in the list. Input The first line contains an integ...
[ { "submission_id": "aoj_ALDS1_1_C_11063301", "code_snippet": "#include<bits/stdc++.h> \nusing namespace std;\nint gcd(int a, int b) {\n while (b != 0) {\n int temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n}\nint lcm(int a, int b) {\n return a / gcd(a, b) * b;\n}\nint m...
aoj_ALDS1_4_C_cpp
Search III Your task is to write a program of a simple dictionary which implements the following instructions: insert str : insert a string str in to the dictionary find str : if the distionary contains str , then print ' yes ', otherwise print ' no ' Input In the first line n , the number of instructions is given. In ...
[ { "submission_id": "aoj_ALDS1_4_C_11057022", "code_snippet": "// ██████████████████╗█████╗███╗ ██╗ ██████╗ █████╗████╗ ██╗█████╗███╗ ██╗\n// ╚══██╔══██╚══██╔══██╔══██████╗ ██║ ██╔══████╔══████╚██╗ ██╔██╔══██████╗ ██║\n// ██║ ██║ ██║ █████████╔██╗ ██║ ██████╔█████████║╚████╔╝█████████╔...
aoj_ALDS1_4_B_cpp
Search II You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q i...
[ { "submission_id": "aoj_ALDS1_4_B_11066403", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nint main() {\n int n,q; cin>>n;\n int s[n+5], t;\n int count=0;\n\n for(int i =1; i<=n;i++){\n cin>>s[i];\n }\n cin>>q;\n for(int i=1;i<=q;i++){\n...
aoj_ALDS1_3_C_cpp
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: insert x: insert an element with key x into the front of the list. delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. ...
[ { "submission_id": "aoj_ALDS1_3_C_11042443", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nint n, x;\nstring s;\nlist<int> l;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0); cout.tie(0);\n\n cin >> n;\n while(n--) {\n cin >> s;\n if(s == \"insert...
aoj_ALDS1_4_D_cpp
Allocation You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packag...
[ { "submission_id": "aoj_ALDS1_4_D_10995248", "code_snippet": "#include<iostream>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nint main(){\n int BaggageCount, TrackCount;\n cin >> BaggageCount >> TrackCount;\n vector<int> BaggageWeights(BaggageCount);\n for (int i = 0; i < Baggag...
aoj_ALDS1_3_B_cpp
There are n processes in a queue. Each process has name i and time i . The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then ...
[ { "submission_id": "aoj_ALDS1_3_B_11064149", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\nconst int mod = 1000000007;\n#define srt(v) sort(v.begin(), v.end());\n#define srt_Dec(v) sort(v.begin(), v.end(), greater<int>());\n\nint solve1(){\n\n return 0;\n}\nint...
aoj_ALDS1_5_A_cpp
Exhaustive Search Write a program which reads a sequence A of n elements and an integer M , and outputs " yes " if you can make M by adding elements in A , otherwise " no ". You can use an element only once. You are given the sequence A and q questions where each question contains M i . Input In the first line n is giv...
[ { "submission_id": "aoj_ALDS1_5_A_11061393", "code_snippet": "# include <stdio.h>\n\nstatic int N, A[50];\n\nstatic int solve(int i, int m)\n{\n if (m == 0)\n return 1;\n if (i >= N)\n return 0;\n\n /* A[i]を使用するか、しないか */\n int res = (solve(i + 1, m) || solve(i + 1, m - A[i]));\n ...
aoj_ALDS1_5_B_cpp
Merge Sort Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for ...
[ { "submission_id": "aoj_ALDS1_5_B_11061501", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nlong long cnt = 0;\n\nvoid merge(vector<int> &A, int left, int mid, int right) {\n int n1 = mid - left;\n int n2 = right - mid;\n\n vector<int> L(n1 + 1), R(n2 + 1);\n\n for (int i = 0...
aoj_ALDS1_6_B_cpp
Partition Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[...
[ { "submission_id": "aoj_ALDS1_6_B_11066645", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\n\nint partition(vector<int>& A, int p, int r) {\n int x = A[r]; // pivot\n int i = p - 1;\n for (int j = p; j <= r - 1; j++) {\n if (A[j] <= x) {\n i++;...
aoj_ALDS1_6_C_cpp
Quick Sort Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i...
[ { "submission_id": "aoj_ALDS1_6_C_11066665", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Card {\n char suit;\n int value;\n};\n\n// partition (ALDS1_6_B 準拠)\nint partition(vector<Card> &A, int p, int r) {\n int x = A[r].value;\n int i = p - 1;\n for (int j = p; j...
aoj_ALDS1_5_D_cpp
The Number of Inversions For a given sequence $A = \{a_0, a_1, ... a_{n-1}\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number o...
[ { "submission_id": "aoj_ALDS1_5_D_11047972", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing ld = long double;\nusing vi = vector<int>;\nusing vvi = vector<vector<int>>;\nusing vvvi = vector<vector<vector<int>>>;\nusing vll = vector<ll>;\nusing vvll = vector<v...
aoj_ALDS1_6_A_cpp
Counting Sort Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into it...
[ { "submission_id": "aoj_ALDS1_6_A_11013399", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvector<int> counting_sort(vector<int>& a, int k)\n{\n vector<int> c;\n c.assign(k+1, 0);\n\n for (int j = 0; j < a.size(); j++)\n c[a[j]]++;\n\n for (int i = 0; i <= k; i++)\n ...
aoj_ALDS1_7_A_cpp
Rooted Trees A graph G = ( V , E ) is a data structure where V is a finite set of vertices and E is a binary relation on V represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs). Fig. 1 A free tree is a connnected, acyclic, undirected graph. A rooted tree is a free tree in which one of the ...
[ { "submission_id": "aoj_ALDS1_7_A_11041298", "code_snippet": "#include<iostream>\nusing namespace std;\nstatic const int MAX = 100005;\nstatic const int NIL = -1;\n\nstruct Node {int p, l, r;};\n\nNode T[MAX];\nint n, D[MAX];\n\nvoid print(int u){\n int i,c;\n cout << \"node \" << u << \": \";\n co...
aoj_ALDS1_8_A_cpp
Binary Search Tree I Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in ...
[ { "submission_id": "aoj_ALDS1_8_A_11016963", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct binary_node\n{\n int id;\n binary_node* parent;\n binary_node* left;\n binary_node* right;\n\n int key;\n\n void set_left(binary_node& l)\n {\n left = &l;\n }...
aoj_ALDS1_8_B_cpp
Binary Search Tree II Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I. insert $k$: Insert a node containing $k$ as key into $T$. find $k$: Report whether $T$ has a node containing $k$. print : Print the keys of the binary search...
[ { "submission_id": "aoj_ALDS1_8_B_11017045", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct binary_node\n{\n int id;\n binary_node* parent;\n binary_node* left;\n binary_node* right;\n\n int key;\n\n void set_left(binary_node& l)\n {\n left = &l;\n }...
aoj_ALDS1_9_B_cpp
Maximum Heap A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node con...
[ { "submission_id": "aoj_ALDS1_9_B_11055699", "code_snippet": "#include <bits/stdc++.h>\n// #include <boost/multiprecision/cpp_int.hpp>\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nll INF = 2e18;\n#define PI 3.14159265358979323846264338327950l\n// namespace multip = boost::multiprec...
aoj_ALDS1_8_C_cpp
Binary Search Tree III Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II. insert $k$: Insert a node containing $k$ as key into $T$. find $k$: Report whether $T$ has a node containing $k$. delete $k$: Delete a node containing $k$. p...
[ { "submission_id": "aoj_ALDS1_8_C_11025601", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (int i = 0; i < (n); i++)\n#define rep2(i, s, n) for (int i = (s); i < (n); i++)\n\n\n// vectorを出力する\nvoid vecprint(vector<int> vec) {\n rep(i, vec.si...
aoj_ALDS1_8_D_cpp
Treap A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to main...
[ { "submission_id": "aoj_ALDS1_8_D_10850490", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nstruct point{\n\tint a,b;\n\tpoint *l,*r,*pa;\n\tpoint(){l=r=pa=NULL;}\n\tpoint(int aa,int bb):a(aa),b(bb){l=r=pa=NULL;};\n};\npoint *root;\npoint *rightRotate(point *t){\n\tpoint *s=t->l;\n\tt->l=s...
aoj_ALDS1_9_D_cpp
Heap Sort There are a number of sorting algorithms which have different characteristics as follows. Algorithm Time Complexity (Worst) Time Complexity (Average) Stability Memory Efficiency Method Features Insertion Sort ALDS1_1_A O($N^2$) O($N^2$) 〇 〇 Insertion Can be fast for an almost sorted array Bubble Sort ALDS1_2_...
[ { "submission_id": "aoj_ALDS1_9_D_10848487", "code_snippet": "#include <stdio.h>\n#include <stdlib.h>\n#define gc() getchar()\n#define pc(c) putchar(c)\n#define p(i) i/2\n\nvoid out(int a){\n char i = 0, str[10];\n do str[i++] = (a%10)|0x30, a /= 10; while(a > 0);\n while(i--) pc(str[i]);\n}\n\nint...
aoj_ALDS1_12_A_cpp
Minimum Spanning Tree For a given weighted graph $G = (V, E)$, find the minimum spanning tree (MST) of $G$ and print total weight of edges belong to the MST. Input In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the following $n$ lines, a $n \times n$ adjacency matrix $A$ which rep...
[ { "submission_id": "aoj_ALDS1_12_A_10644587", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <map>\n#include <vector>\n\nusing namespace std;\n\nmap<int, vector<int>> vertex;\nmap<int, vector<int>> edge;\nint sum = 0;\n\nstruct UnionFind {\n vector<int> parent, rank;\n\n UnionFin...
aoj_ALDS1_10_D_cpp
Optimal Binary Search Tree Optimal Binary Search Tree is a binary search tree constructed from $n$ keys and $n+1$ dummy keys so as to minimize the expected value of cost for a search operation. We are given a sequence $K = {k_1, k_2, ..., k_n}$ of $n$ distinct keys in sorted order $(k_1 < k_2 < ... < k_n)$, and we wish...
[ { "submission_id": "aoj_ALDS1_10_D_11017187", "code_snippet": "//\n// Created by Manas Choudhary on 04-11-2025 05:05 PM\n//\n#include <algorithm>\n#include <iostream>\n#include <chrono>\n#include <vector>\n#include <cmath>\n#include <unordered_map>\n#include <map>\n#include <queue>\n#define ll long double\n...
aoj_ALDS1_10_C_cpp
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \{a,b,c,b,d,a,b\}$ and $Y = \{b,d,c,a,b,a\}$, the sequence $\{b,c,a\}$ is a common subsequence of both $X$ and $Y$. On the other hand, t...
[ { "submission_id": "aoj_ALDS1_10_C_11058892", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\nusing ll=long long;\nconst ll INF=1ll<<60;\nint main(){\n int q;\n cin>>q;\n while(q--){\n string s,t;\n cin>>s>>t;\n ...
aoj_ALDS1_13_A_cpp
8 Queens Problem The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure. For a given chess board where $k$ queens are already placed,...
[ { "submission_id": "aoj_ALDS1_13_A_10595759", "code_snippet": "#include <iostream>\n#include <vector>\n#include <string>\n#include <cmath>\n#include <algorithm>\n#include <set>\n#include <map>\n#include <queue>\n#include <iomanip>\n#include <functional>\n#include <stack>\n\nusing namespace std;\nusing l = l...
aoj_ALDS1_9_C_cpp
Priority Queue A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations: $insert(S, k)$: insert an element $k$ into the set $S$ $extractMax(S)$: remove and return the element of $S$ with the largest key Write a program whic...
[ { "submission_id": "aoj_ALDS1_9_C_11064162", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\nconst int mod = 1000000007;\n#define srt(v) sort(v.begin(), v.end());\n#define srt_Dec(v) sort(v.begin(), v.end(), greater<int>());\n\nint solve1(){\n\n return 0;\n}\nint...
aoj_ALDS1_12_C_cpp
Single Source Shortest Path II For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$. Input In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the f...
[ { "submission_id": "aoj_ALDS1_12_C_11041168", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<queue>\nusing namespace std;\nstatic const int MAX = 10000;\nstatic const int INFTY = (1<<20);\nstatic const int WHITE = 0;\nstatic const int GRAY = 1;\nstatic const int BLACK = 2;\n\nint n;\nvec...
aoj_ALDS1_11_D_cpp
Connected Components Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network. Input In the first line, two integer $n$ and $m$ are given. $n$ is the number of users in the SNS and $m$ is the number of relations in the SNS...
[ { "submission_id": "aoj_ALDS1_11_D_11066465", "code_snippet": "#include <iostream>\n#include <vector>\n#include <stack>\nusing namespace std;\nstatic const int MAX = 100000;\nstatic const int NIL = -1;\n\nint n;\nvector<int> G[MAX];\nint color[MAX];\n\nvoid dfs(int r, int c) {\n stack<int> S;\n S.push...
aoj_ALDS1_13_B_cpp
8 Puzzle The goal of the 8 puzzle problem is to complete pieces on $3 \times 3$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 8 as shown below. 1 3 0 4 2 5 7 8 6 You can move a piece toward the empty space at one step. Your g...
[ { "submission_id": "aoj_ALDS1_13_B_11010942", "code_snippet": "#include <cstdio>\n#include <queue>\n#include <map>\n#include <string>\n#include <algorithm>\n#include <iostream>\nconst int N=3;//计算零点的上下左右\nconst int N2=9;\nusing namespace std;\nstruct Puzzle{\n int f[N2];//拼图按顺序对应的数字\n int space;//零所在的...
aoj_ALDS1_15_A_cpp
Change-Making Problem You want to make change for $n$ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and/or 25 cents coins respectively, find the minimum number of coins you need. Input $n$ The integer $n$ is given in a line. 出力 Print the minimum number of coins you need in a line. Constraints $1 \l...
[ { "submission_id": "aoj_ALDS1_15_A_10945998", "code_snippet": "#include <stdio.h>\n\nint main(){\n\tint count = 0;\n\tint num;\n\tscanf(\"%d\",&num);\n\twhile(num>0){\n\t\twhile(num>=25){\n\t\t\tnum-= 25;\n\t\t\tcount++;\n\t\t}\n\t\twhile(num >= 10){\n\t\t\tnum-= 10;\n\t\t\tcount++;\n\t\t}\n\t\twhile(num >=...
aoj_ALDS1_13_C_cpp
15 Puzzle The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below. 1 2 3 4 6 7 8 0 5 10 11 12 9 13 14 15 You can move a piece toward the empty sp...
[ { "submission_id": "aoj_ALDS1_13_C_11003707", "code_snippet": "//迭代加深A*/IDA*\n#include <iostream>\n#include <cmath>\n#include <string>\n#include <algorithm>\nusing namespace std;\n#define N 4\n#define N2 16\nconst int LIMIT=100;\nstruct puzzle{\n int f[N2];\n int space;\n int MD;\n};\nint MDT[N2][N...
aoj_ALDS1_14_C_cpp
Pattern Search Find places where a R × C pattern is found within a H × W region. Print top-left coordinates ( i , j ) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and ( H -1, W -1) respectively. Input In the first line, two integers H and W are given. In the ...
[ { "submission_id": "aoj_ALDS1_14_C_10933201", "code_snippet": "#include<iostream>\n#include<vector>\n#include<string>\nusing namespace std;\nusing ull = unsigned long long;\n#define D1 1000000007\n#define D2 2000000011\n\nint main(){\n\tint H, W;\n\tcin >> H >> W;\n\tvector<string> str(H);\n\tfor(auto& i : ...
aoj_ALDS1_14_B_cpp
String Search Find places where a string P is found within a text T . Print all indices of T where P found. The indices of T start with 0. Input In the first line, a text T is given. In the second line, a string P is given. Output Print an index of T where P found in a line. Print the indices in ascending order. Cons...
[ { "submission_id": "aoj_ALDS1_14_B_10961094", "code_snippet": "#include <iostream>\n#include <string>\nusing namespace std;\n\n// 失敗関数fの計算\nvoid compf(string p, int f[])\n{\n\tf[0] = -1;\n\t\n\tfor(int i=1; i<p.size()+1; i++){\n\t\tint j = f[i-1];\t\t\t\t\t// 1文字前のf\n\t\t\n\t\twhile(j>=0 && p[i-1]!=p[j]){\n...
aoj_DSL_1_B_cpp
Weighted Union Find Trees There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following information and questions. relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$ diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$ Input $n \; q$ $query_1$ $query_2$ : $query_q$ In the first l...
[ { "submission_id": "aoj_DSL_1_B_11052170", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nstruct Weighted_UnionFind {\n vector<int> par, rank, siz;\n vector<ll> weight;\n\n Weighted_UnionFind(int N) : par(N,-1), rank(N, 0), siz(N,1), weight(N,0) {}\n \n...
aoj_DSL_1_A_cpp
Disjoint Set Write a program which manipulates a disjoint set S = {S 1 , S 2 , . . . , S k } . First of all, the program should read an integer n , then make a disjoint set where each element consists of 0, 1, ... n−1 respectively. Next, the program should read an integer q and manipulate the set for q queries. There a...
[ { "submission_id": "aoj_DSL_1_A_11063815", "code_snippet": "#include <iostream>\n#include <vector>\n#include <cstdint>\n\nnamespace uft { // mst.cc で merge 関数を使用するために、名前空間を定義する\n\nuint16_t root(uint16_t idx, std::vector<uint16_t>& parent) {\n if (parent[idx] == idx) { // 親が自分自身の場合\n return idx;\n ...
aoj_DSL_2_A_cpp
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = { a 0 , a 1 , . . . , a n-1 } with the following operations: find(s, t) : report the minimum element in a s , a s+1 , . . . ,a t . update(i, x) : change a i to x . Note that the initial values of a i ( i = 0, 1, . . . , n−1 ) are 2 31 -1. Inp...
[ { "submission_id": "aoj_DSL_2_A_11066373", "code_snippet": "#ifndef ATCODER_INTERNAL_BITOP_HPP\n#define ATCODER_INTERNAL_BITOP_HPP 1\n\n#ifdef _MSC_VER\n#include <intrin.h>\n#endif\n\n#if __cplusplus >= 202002L\n#include <bit>\n#endif\n\nnamespace atcoder {\n\nnamespace internal {\n\n#if __cplusplus >= 2020...
aoj_ALDS1_14_D_cpp
String Search Determine whether a text T includes a pattern P . Your program should answer for given queries consisting of P_i . Input In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively. Output...
[ { "submission_id": "aoj_ALDS1_14_D_10853897", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(a) a.begin(), a.end()\n#define MS(m,v) memset(m,v,sizeof(m))\ntypedef long long ll;\ntypedef lo...
aoj_DSL_2_B_cpp
Range Sum Query Write a program which manipulates a sequence A = { a 1 , a 2 , . . . , a n } with the following operations: add(i, x) : add x to a i . getSum(s, t) : print the sum of a s , a s+1 ,...,a t . Note that the initial values of a i ( i = 1, 2, . . . , n ) are 0. Input n q com 1 x 1 y 1 com 2 x 2 y 2 ... com q...
[ { "submission_id": "aoj_DSL_2_B_11059888", "code_snippet": "#include <bits/stdc++.h>\n#include <bit>\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\nusing ld = long double;\nusing i128 = __int128_t;\nusing u128 = __uint128_t;\nusing pii = pair<int, int>;\nusing pic = pair<int,...
aoj_DSL_2_C_cpp
Range Search (kD Tree) The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider insert and delete operations for the set. Inp...
[ { "submission_id": "aoj_DSL_2_C_11053254", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Point {\n int x, y, idx;\n};\n\nstruct KDNode {\n Point p;\n KDNode *left, *right;\n int minX, maxX, minY, maxY;\n\n KDNode() : left(nullptr), right(nullptr) {}\n};\n\nbool cmp...
aoj_ALDS1_15_B_cpp
Fractional Knapsack Problem You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight. When you put some items into the knapsack, the following conditions must be satisfied: The total value of the items is as large as possibl...
[ { "submission_id": "aoj_ALDS1_15_B_11063373", "code_snippet": "#define _USE_MATH_DEFINES\n#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef struct items{\n int v;\n int w;\n float r;\n int s=0;\n\n}it;\n\nint main (){\n int n, c, tw=0;\n double sum=0;\n it x[100000];\n\n cin >...
aoj_ALDS1_15_C_cpp
Activity Selection Problem There are $n$ acitivities with start times $\{s_i\}$ and finish times $\{t_i\}$. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be performed by a single person. Input $n$ $s_1$ $t_1$ $s_2$ $t_2$ : $s_n$ $t_n$ The first line ...
[ { "submission_id": "aoj_ALDS1_15_C_11063446", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef struct time{\n int s;\n int f;\n}tym;\n\nint main(){\n int n, c=1;\n tym t[100000];\n cin >> n;\n\n for(int i=0; i<n; i++){\n cin >> t[i].s >> t[i].f;\n }\n\n ...
aoj_DSL_3_C_cpp
The Number of Windows For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a_{r-1} + a_r \leq x_i$. Constraints $1 \leq ...
[ { "submission_id": "aoj_DSL_3_C_11066206", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n#define FOR(i,a,b) for(int i=a;i<b;i++)\n#define ROF(i,a,b) for(int i=b-1;i>=a;i--) \n#define vecin(vec,n) for(int i=0;i<n;i++) cin>>...
aoj_DSL_4_A_cpp
Union of Rectangles Given a set of $N$ axis-aligned rectangles in the plane, find the area of regions which are covered by at least one rectangle. Input The input is given in the following format. $N$ $x1_1$ $y1_1$ $x2_1$ $y2_1$ $x1_2$ $y1_2$ $x2_2$ $y2_2$ : $x1_N$ $y1_N$ $x2_N$ $y2_N$ ($x1_i, y1_i$) and ($x2_i, y2_i$)...
[ { "submission_id": "aoj_DSL_4_A_11064592", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (int i = 0; i < n; ++i)\n\nint main() {\n int N;\n cin >> N;\n vector<int> X1, X2, Y1, Y2, X, Y;\n rep(i, N) {\n int x1, y1, x2, y2;\n...
aoj_DSL_5_B_cpp
The Maximum Number of Overlaps Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals. Input The input is given in the following format. $N$ $x1_1$ $y1_1$ $x2_1$ $y2_1$ $x1_2$ $y1_2$ $x2_2$ $y2_2$ : $x1_N$ $y1_N$ $x2_N$ $y2_N...
[ { "submission_id": "aoj_DSL_5_B_11044734", "code_snippet": "// --- Start of include: ./../../akakoi_lib/template/template.cpp ---\n// #pragma GCC target(\"avx2\")\n// #pragma GCC optimize(\"O3,unroll-loops\")\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i,n) for(ll i=0...
aoj_DSL_5_A_cpp
The Maximum Number of Customers $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints $ 1 \leq N \leq 10^5 $ $ 1 \leq T \leq 10^5 $ $ 0 \leq l_i < r_i \leq T $...
[ { "submission_id": "aoj_DSL_5_A_10994563", "code_snippet": "#define _USE_MATH_DEFINES\n#include<bits/stdc++.h>\n#define OVERLOAD_REP(v1, v2, v3, v4, NAME, ...) NAME\n#define REP1(i, n) for (int i = 0; (i) < (n); ++(i))\n#define REP2(i, l, r) for (int i = (l); (i) < (r); ++(i))\n#define REP3(i, l, r, d) for ...
aoj_GRL_1_B_cpp
Single Source Shortest Path (Negative Edges) Input An edge-weighted graph G ( V , E ) and the source r . | V | | E | r s 0 t 0 d 0 s 1 t 1 d 1 : s |E|-1 t |E|-1 d |E|-1 |V| is the number of vertices and |E| is the number of edges in G . The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is th...
[ { "submission_id": "aoj_GRL_1_B_10447635", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\ntypedef pair<ll, ll> P;\n\nint main() {\n ll n, m, s;\n cin >> n >> m >> s;\n\n const ll INF = 8e18;\n vector<vector<ll>> dist(n,vector<ll>(n,INF));\n for (ll i =...
aoj_DSL_3_B_cpp
The Smallest Window II For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints $1 \leq N \leq 10^5$...
[ { "submission_id": "aoj_DSL_3_B_10994705", "code_snippet": "///***....... In the name of Allah ......***////\n/*...Free Palestine..........Free Al_Aqsa.....*/\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n#define F first\n#define S second\n#define yes cout<<\"YES\"<<endl\n#...
aoj_GRL_1_C_cpp
All Pairs Shortest Path Input An edge-weighted graph G ( V , E ). | V | | E | s 0 t 0 d 0 s 1 t 1 d 1 : s |E|-1 t |E|-1 d |E|-1 |V| is the number of vertices and |E| is the number of edges in G . The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. s i and t i represent source and target vertices...
[ { "submission_id": "aoj_GRL_1_C_10776003", "code_snippet": "// https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_C\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <climits>\n#include <queue>\nusing namespace std;\n\nstruct Edge\n{\n int s = 0, t = 0;\n int d = 0;\n...
aoj_DSL_3_A_cpp
The Smallest Window I For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. Constraints $1 \leq N \leq 10^5$ $1 \leq S \leq 10^9$...
[ { "submission_id": "aoj_DSL_3_A_10929127", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int N, S;\n cin >> N >> S;\n vector<int> a(N);\n for(auto& i : a) cin >> i;\n int ans = 1000000000;\n for(int s = 0, t = 0, sum = 0; t < N;){\n sum += a[t];\n ...
aoj_GRL_1_A_cpp
Single Source Shortest Path For a given weighted graph G(V, E) and a source r , find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path). Input An edge-weighted graph G ( V , E ) and the source r . | V | | E | r s 0 t 0 d 0 s 1 t 1 d 1 : s |E|-1 t |E|-1 d |E|-1 |V| is the number ...
[ { "submission_id": "aoj_GRL_1_A_11064891", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nusing P=pair<ll,int>;\n\nint main(){\n int V, E, r;\n cin >> V >> E >> r;\n vector<vector<P>> G(V,vector<P>(0));\n for(int i=0; i<E; i++){\n int s, t;\n ...
aoj_GRL_2_A_cpp
Minimum Spanning Tree Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = ( V , E ). Input |V| |E| s 0 t 0 w 0 s 1 t 1 w 1 : s |E|-1 t |E|-1 w |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with th...
[ { "submission_id": "aoj_GRL_2_A_11063691", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint MAX_WEIGHT = 10000;\n\nstruct Node\n{\n vector<pair<int, int>> children; // destination node, weight\n};\n\nvoid tmp(const vector<Node> &nodes, vector<int>...
aoj_GRL_3_A_cpp
Articulation Points Find articulation points of a given undirected graph G(V, E) . A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph. Input |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the g...
[ { "submission_id": "aoj_GRL_3_A_11037910", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> br;\nvector<vector<int>> adj;\nint Time=0;\nvector<int> low, disc;\n\nvoid dfsBR(int u, int p) {\n low[u] = disc[u] = ++Time; int c=0;\n for (int& v : adj[u]) {\n if (v == p) continu...
aoj_GRL_3_B_cpp
Bridges Find bridges of an undirected graph G(V, E) . A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components. Input |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 , where |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with ...
[ { "submission_id": "aoj_GRL_3_B_11030221", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nvector<pair<int, int>> br;\nvector<vector<int>> adj;\nint Time=0;\nvector<int> low, disc;\n\nvoid dfsBR(int u, int p) {\n low[u] = disc[u] = ++Time;\n for (int& v : adj[u]) {\n if (v == p) conti...
aoj_GRL_3_C_cpp
Strongly Connected Components A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. Input A directed graph G(V, E) and a sequence of queries where each query contains a pair ...
[ { "submission_id": "aoj_GRL_3_C_11053568", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n// #include \"all.h\"\n\n#define int long long\n#define uint unsigned int\n#define all(x) (x).begin(), (x).end()\n#define rall(x) (x).rbegin(), (x).rend()\n#define is2pow(n) (n && (!(n & (n - 1))))\...
aoj_GRL_5_A_cpp
Diameter of a Tree Given a tree T with non-negative weight, find the diameter of the tree. The diameter of a tree is the maximum distance between two nodes in a tree. Input n s 1 t 1 w 1 s 2 t 2 w 2 : s n-1 t n-1 w n-1 The first line consists of an integer n which represents the number of nodes in the tree. Every node ...
[ { "submission_id": "aoj_GRL_5_A_11059886", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nstruct Node\n{\n vector<pair<int, int>> children; // destination node, length\n int length;\n};\n\npair<int, int> theFurthest(const vector<Node> &nodes, int...
aoj_GRL_5_B_cpp
Height of a Tree Given a tree T with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node. Input n s 1 t 1 w 1 s 2 t 2 w 2 : s n-1 t n-1 w n-1 The first line consists of an integer n which represents the number of nodes in the tr...
[ { "submission_id": "aoj_GRL_5_B_10853207", "code_snippet": "#include <iostream>\n#include <vector>\n#include <cstring>\n\n#define MAXN 10000\n\nusing namespace std;\n\nstruct edge{\n\tint nn;\n\tint w;\n\tedge(int a, int b){nn = a; w = b;}\n};\n\nvector<edge> node[MAXN];\n\nint maxdist[MAXN];\nint visited[M...
aoj_GRL_4_B_cpp
Topological Sort A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You ...
[ { "submission_id": "aoj_GRL_4_B_11066613", "code_snippet": "#include <iostream>\n#include <vector>\n#include <climits>\n#include <queue>\n#include <algorithm>\nusing namespace std;\nconst int MAXVEX = 10000;\n\n// 需要有向无环图\n\nclass Graph {\npublic:\n int n; // 顶点数\n int m; // 边数\n vector<vector<int>...
aoj_GRL_5_C_cpp
LCA: Lowest Common Ancestor For a rooted tree, find the lowest common ancestor of two nodes u and v . The given tree consists of n nodes and every node has a unique ID from 0 to n -1 where 0 is the root. Input n k 0 c 1 c 2 ... c k 0 k 1 c 1 c 2 ... c k 1 : k n-1 c 1 c 2 ... c k n-1 q u 1 v 1 u 2 v 2 : u q v q The firs...
[ { "submission_id": "aoj_GRL_5_C_11049323", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing ld = long double;\nusing vi = vector<int>;\nusing vvi = vector<vector<int>>;\nusing vvvi = vector<vector<vector<int>>>;\nusing vll = vector<ll>;\nusing vvll = vector<vec...
aoj_DPL_1_B_cpp
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value v i and weight w i . You want to find a subset of items to put such that: The total value of the items is as large as possible. The items have combined weight at most W , that is capacity of the knapsack. Find the maximum ...
[ { "submission_id": "aoj_DPL_1_B_11009038", "code_snippet": "/*\nAllaih is Almighty\nBismillahhi Rahmanir Rahim\nBaishakh\n*/\n#include<bits/stdc++.h>\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef tree<int, null_type,...
aoj_GRL_6_B_cpp
Minimum Cost Flow Find the minimum cost to send a certain amount of flow through a flow network. The flow network is a directed graph where each edge $e$ has capacity $c(e)$ and cost $d(e)$. Each edge $e$ can send an amount of flow $f(e)$ where $f(e) \leq c(e)$. Find the minimum value of $\sum_{e} (f(e) \times d(e))$ t...
[ { "submission_id": "aoj_GRL_6_B_8449576", "code_snippet": "#line 1 \"playspace/main.cpp\"\n#include <bits/stdc++.h>\n#line 2 \"library/gandalfr/graph/flow_graph.hpp\"\n\n#line 7 \"library/gandalfr/graph/base_graph.hpp\"\n\nnamespace internal {\ntemplate <class Weight> struct _base_edge {\n int v[2];\n ...
aoj_DPL_1_C_cpp
Knapsack Problem You have N kinds of items that you want to put them into a knapsack. Item i has value v i and weight w i . You want to find a subset of items to put such that: The total value of the items is as large as possible. The items have combined weight at most W , that is capacity of the knapsack. You can sele...
[ { "submission_id": "aoj_DPL_1_C_10925361", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\n#define all(T) T.begin(), T.end()\nusing ll = long long;\nusing P = pair<int, int>;\nconst int di[] = {-1, 0, 1, 0};\nconst int dj[] = {0, -1, 0, ...
aoj_DPL_1_A_cpp
Coin Changing Problem Find the minimum number of coins to make change for n cents using coins of denominations d 1 , d 2 ,.., d m . The coins can be used any number of times. Input n m d 1 d 2 ... d m Two integers n and m are given in the first line. The available denominations are given in the second line. Output Prin...
[ { "submission_id": "aoj_DPL_1_A_10998405", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <cstdio>\n#include <iostream>\n#include <stack>\n#include <queue>\n#include <algorithm>\n#include <functional>\n#include <set>\n#include <map>\n#include <string>\n#include <vector>\n#include <cmath>\n#inclu...
aoj_GRL_7_A_cpp
Bipartite Matching A bipartite graph G = (V, E) is a graph in which the vertex set V can be divided into two disjoint subsets X and Y such that every edge e ∈ E has one end point in X and the other end point in Y . A matching M is a subset of edges such that each node in V appears in at most one edge in M . Given a bip...
[ { "submission_id": "aoj_GRL_7_A_8843369", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct io_setup {\n io_setup() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout << fixed << setprecision(15);\n }\n} io_setup;\n\ntemplate <typename T>\nvoid p...
aoj_GRL_6_A_cpp
Maximum Flow A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$. Input A flow ...
[ { "submission_id": "aoj_GRL_6_A_11057074", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 1e9;\n\nstruct Edge {\n int to; //行き先\n int rev; //逆辺のindex\n int cap; //容量\n};\n\nstruct MaxFlow {\n int N;\n vector<vector<Edge>> graph;\n vector<bool> used;\n\n ...
aoj_DPL_2_B_cpp
Chinese Postman Problem For a given weighted undirected graph G(V, E) , find the distance of the shortest route that meets the following criteria: It is a closed cycle where it ends at the same point it starts. The route must go through every edge at least once. Input |V| |E| s 0 t 0 d 0 s 1 t 1 d 1 : s |E|-1 t |E|-1 d...
[ { "submission_id": "aoj_DPL_2_B_6761389", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std ;\n#define MAX 1000000001\n#define NIL -2000000002\n#define INF 1e9\n#define MAXN 20\ntypedef long long int ll;\nconst int debug = 0 ; \nconst int debug1 = 0 ; \n#define REP(i,n) for(int i=0; i<(int)n; i...
aoj_DPL_2_A_cpp
Traveling Salesman Problem For a given weighted directed graph G(V, E) , find the distance of the shortest route that meets the following criteria: It is a closed cycle where it ends at the same point it starts. It visits each vertex exactly once. Input |V| |E| s 0 t 0 d 0 s 1 t 1 d 1 : s |E|-1 t |E|-1 d |E|-1 |V| is t...
[ { "submission_id": "aoj_DPL_2_A_11044370", "code_snippet": "// https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_2_A&lang=ja\n#include <iostream>\n#include <vector>\n#include <climits>\n\nusing namespace std;\n\nint main(){\n int node, edge;\n cin >> node >> edge;\n vector<vector<int>> ...
aoj_DPL_3_A_cpp
Largest Square Given a matrix ( H × W ) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s. Input H W c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W In the first line, two integers H and W separated by a space character are given. In the following H lines...
[ { "submission_id": "aoj_DPL_3_A_11010294", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std ;\n#define pb push_back\n#define ll long long \nconst ll mod = 1e9+7;\n\nbool check(ll x , ll n, ll m, vector<vector<ll>>&ps){\n for(ll i=0;i+x-1<n;i++){\n for(ll j=0;j+x-1<m;j++){\n ...
aoj_DPL_2_C_cpp
Bitonic Traveling Salesman Problem (Bitonic TSP) For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria: Visit the points according to the following steps: It starts from the leftmost point (starting point), goes strictly from left to right, and then vis...
[ { "submission_id": "aoj_DPL_2_C_10868658", "code_snippet": "#include <bits/stdc++.h>\n#define reb(i,n) for (int i = 0; i < (n); i++)\n#define rep(i, n0, n) for (int i = (n0); i < (n); i++)\n#define repp(i, n0, n) for (int i = (n0); i <= (n); i++)\n#define rrep(i, n0, n) for (int i = (n0); i >= (n); i--) \n#...
aoj_DPL_3_B_cpp
Largest Rectangle Given a matrix ( H × W ) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Input H W c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W In the first line, two integers H and W separated by a space character are given. In the following H lines,...
[ { "submission_id": "aoj_DPL_3_B_10988570", "code_snippet": "#include <cstdio>\n#include <stack>\nusing namespace std;\nconst int maxv=1401;\nint C[maxv][maxv];\nint D[maxv][maxv];\nint H,W;\nint maxsquare(){\n int largest=0;\n for(int i=0;i<H;i++){\n stack<pair<int,int>> rect;\n for(int ...
aoj_DPL_5_A_cpp
Balls and Boxes 1 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes...
[ { "submission_id": "aoj_DPL_5_A_9527776", "code_snippet": "/*\n Created by Pujx on 2024/8/4.\n*/\n#pragma GCC optimize(2, 3, \"Ofast\", \"inline\")\n#include <bits/stdc++.h>\nusing namespace std;\n#define endl '\\n'\n//#define int long long\n//#define double long double\nusing i64 = long long;\nusing ui6...
aoj_DPL_4_B_cpp
Coin Combination Problem II You have N coins each of which has a value a i . Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R . Constraints 1 ≤ K ≤ N ≤ 40 1 ≤ a i ≤ 10 16 1 ≤ L ≤ R ≤ 10...
[ { "submission_id": "aoj_DPL_4_B_11055869", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing ld = long double;\nusing vi = vector<int>;\nusing vvi = vector<vector<int>>;\nusing vvvi = vector<vector<vector<int>>>;\nusing vll = vector<ll>;\nusing vvll = vector<vec...
aoj_CGL_3_C_cpp
Polygon-Point-Containment For a given polygon g and target points t , print "2" if g contains t , "1" if t is on a segment of g , "0" otherwise. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≤ i ≤ n-1 ) are sides of the polygon. The line segment connecting ...
[ { "submission_id": "aoj_CGL_3_C_10650599", "code_snippet": "# 1 \"tmp.cpp\"\n#include <bits/stdc++.h>\nusing namespace std;\n#include <atcoder/all>\nusing namespace atcoder;\n#define ll long long\n#define ld long double\n#define out(x) cout<<x<<'\\n'\n#define all(v) v.begin(),v.end()\n#define rep(i,n) for(i...
aoj_DPL_4_A_cpp
Coin Combination Problem You have 4 bags A, B, C and D each of which includes N coins (there are totally 4N coins). Values of the coins in each bag are a i , b i , c i and d i respectively. Find the number of combinations that result when you choose one coin from each bag (totally 4 coins) in such a way that the total ...
[ { "submission_id": "aoj_DPL_4_A_10881124", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\n\nint main(){\n ll N,V; cin>>N>>V;\n vector<ll> A(N),B(N),C(N),D(N);\n for(ll& a:A) cin>>a;\n for(ll& a:B) cin>>a;\n for(ll& a:C) cin>>a;\n for(ll& a:D) cin>>a;\...
aoj_DPL_3_C_cpp
Largest Rectangle in a Histogram A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints $1 \leq N \leq 10^5$ $0 \leq h_i ...
[ { "submission_id": "aoj_DPL_3_C_11004547", "code_snippet": "#include <iostream>\n#include <stack>\n#include <vector>\n#include <utility>\n#define ll long long\nusing namespace std;\n\n// 自身より左にあって自身より小さい要素が一番最後に出てくるインデックス\nvector<int> find_small_left(const vector<ll>& hist){\n stack<pair<ll,int>> s; // p...
aoj_CGL_4_C_cpp
Convex Cut As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≤ i ≤ n−1 ) are sides of the convex polygon. The l...
[ { "submission_id": "aoj_CGL_4_C_6666641", "code_snippet": "//my geometry template\n\n#include<bits/stdc++.h>\n//#define double long double\nusing namespace std;\ndouble const INF=1e20;\nint const N=233333;\ndouble const PI=acos(-1.0),EPS=1e-10;\nint les(double x,double y){\n\treturn x<y-EPS;\n}\nint leq(dou...
aoj_DPL_5_B_cpp
Balls and Boxes 2 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes...
[ { "submission_id": "aoj_DPL_5_B_9527781", "code_snippet": "/*\n Created by Pujx on 2024/8/4.\n*/\n#pragma GCC optimize(2, 3, \"Ofast\", \"inline\")\n#include <bits/stdc++.h>\nusing namespace std;\n#define endl '\\n'\n//#define int long long\n//#define double long double\nusing i64 = long long;\nusing ui6...
aoj_DPL_5_C_cpp
Balls and Boxes 3 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes...
[ { "submission_id": "aoj_DPL_5_C_10681358", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#line 2 \"modint/montgomery-modint.hpp\"\n\ntemplate <uint32_t mod>\nstruct LazyMontgomeryModInt {\n using mint = LazyMontgomeryModInt;\n using i32 = int32_t;\n using u32 = uint32_t;\n using u64 =...
aoj_CGL_7_B_cpp
Incircle of a Triangle Write a program which prints the central coordinate ($cx$,$cy$) and the radius $r$ of a incircle of a triangle which is constructed by three points ($x_1$, $y_1$), ($x_2$, $y_2$) and ($x_3$, $y_3$) on the plane surface. Input The input is given in the following format $x_1$ $y_1$ $x_2$ $y_2$ $x_3...
[ { "submission_id": "aoj_CGL_7_B_10750421", "code_snippet": "#include <bits/stdc++.h>\n\n// from: cpp.json\n#define INF 8e18\n#define int long long\n#define LD long double\nusing namespace std;\n\nvoid solve() {\n LD x1, y1, x2, y2, x3, y3;\n cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;\n\n auto dist = ...
aoj_CGL_4_A_cpp
Convex Hull Find the convex hull of a given set of points P . In other words, find the smallest convex polygon containing all the points of P . Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the co...
[ { "submission_id": "aoj_CGL_4_A_11065485", "code_snippet": "#include <bits/stdc++.h>\n\n#define debug(a) cout << #a << \" = \" << (a) << ' '\n\nusing namespace std;\n\n#define db long double\n// #define db long long\n\nconst db EPS = 1e-9;\n\n#define cross(p1, p2, p3) (p2 - p1).det(p3 - p1)\n#define crossop...
aoj_NTL_1_B_cpp
Power For given integers m and n , compute m n (mod 1,000,000,007). Here, A (mod M ) is the remainder when A is divided by M . Input m n Two integers m and n are given in a line. Output Print m n (mod 1,000,000,007) in a line. Constraints 1 ≤ m ≤ 100 1 ≤ n ≤ 10 9 Sample Input 1 2 3 Sample Output 1 8 Sample Input 2 5 8 ...
[ { "submission_id": "aoj_NTL_1_B_10672756", "code_snippet": "// This is free and unencumbered software released into the public domain.\n\n// Anyone is free to copy, modify, publish, use, compile, sell, or\n// distribute this software, either in source code form or as a compiled\n// binary, for any purpose, ...
aoj_CGL_4_B_cpp
Diameter of a Convex Polygon Find the diameter of a convex polygon g . In other words, find a pair of points that have maximum distance between them. Input n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points in g . In the following lines, the coordinate of the i -th point p i is given by two real nu...
[ { "submission_id": "aoj_CGL_4_B_11065558", "code_snippet": "#include <bits/stdc++.h>\n\n#define debug(a) cout << #a << \" = \" << (a) << ' '\n\nusing namespace std;\n\n#define db long double\n// #define db long long\n\nconst db EPS = 1e-9;\n\n#define cross(p1, p2, p3) (p2 - p1).det(p3 - p1)\n#define crossop...
aoj_CGL_5_B_cpp
Minimum Enclosing Circle There are $N$ points on a two-dimensional plane. Find the smallest circle that encloses all of these points. Such a circle is called the Minimum Enclosing Circle. A Minimum Enclosing Circle can be efficiently found using an algorithm based on the following properties. Let the sequence of $N$ po...
[ { "submission_id": "aoj_CGL_5_B_11065578", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define pii pair<int, int>\n#define pll pair<ll, ll>\n#define vi vector<int>\n#define vl vector<ll>\n#define ov4(a, b, c, d, name, ...) name\n#define rep3(i, a, b, c) for(ll i = ...
aoj_CGL_5_A_cpp
Closest Pair For given n points in metric space, find the distance of the closest points. Input n x 0 y 0 x 1 y 1 : x n-1 y n-1 The first integer n is the number of points. In the following n lines, the coordinate of the i -th point is given by two real numbers x i and y i . Each value is a real number with at most 6 d...
[ { "submission_id": "aoj_CGL_5_A_11065295", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define pii pair<int, int>\n#define pll pair<ll, ll>\n#define vi vector<int>\n#define vl vector<ll>\n#define ov4(a, b, c, d, name, ...) name\n#define rep3(i, a, b, c) for(ll i = ...
aoj_NTL_1_C_cpp
Least Common Multiple Find the least common multiple (LCM) of given n integers. Input n a 1 a 2 ... a n n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Constraints 2 ≤ n ≤ 10 1 ≤ a i ≤ 1000 Product of given integers a i...
[ { "submission_id": "aoj_NTL_1_C_8308574", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\nint main() {\n int n;\n cin >> n;\n \n vector<int> nums(n);\n cin >> nums[0];\n for (int i = 1; i < n; i++) {\n cin >> nums[i];\n int a = nums[i];\n ...
aoj_NTL_1_A_cpp
Prime Factorization Factorize a given integer n . Input n An integer n is given in a line. Output Print the given integer n and : . Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before e...
[ { "submission_id": "aoj_NTL_1_A_10778330", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main()\n{\n int n;\n cin >> n;\n int l = n;\n int i = 3;\n int flag = 0;\n cout << n << \":\";\n while (n % 2 == 0) {\n cout << \" 2\";\n n /= 2;\n }\n\n ...
aoj_CGL_6_A_cpp
Segment Intersections: Manhattan Geometry For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them. Input In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following forma...
[ { "submission_id": "aoj_CGL_6_A_11047895", "code_snippet": "// --- Start of include: ./../../akakoi_lib/template/template.cpp ---\n// #pragma GCC target(\"avx2\")\n// #pragma GCC optimize(\"O3,unroll-loops\")\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i,n) for(ll i=0...
aoj_NTL_2_B_cpp
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the difference in a line. Constraints $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 -3 Sampl...
[ { "submission_id": "aoj_NTL_2_B_10774191", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\n#include<string>\n#include<cmath>\n#include<iomanip>\n#include<map>\n#include<stack>\n#include<queue>\n#include<set>\n#include<deque>\n#include<list>\n#include<bitset>\nusing namespace std;...
aoj_NTL_2_A_cpp
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 Sample Input 2 100 25...
[ { "submission_id": "aoj_NTL_2_A_10774189", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\n#include<string>\n#include<cmath>\n#include<iomanip>\n#include<map>\n#include<stack>\n#include<queue>\n#include<set>\n#include<deque>\n#include<list>\n#include<bitset>\nusing namespace std;...
aoj_0030_cpp
整数の和 0 から 9 の数字から異なる n 個の数を取り出して合計が s となる組み合わせの数を出力するプログラムを作成してください。 n 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、 n が 3 で s が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 の 3 通りとなります。 Input 複数のデータセットが与えられます。各データセットに n (1 ≤ n ≤ 9) と s (0 ≤ s ≤ 100) が1つのスペースで区切られて1行に与えられます。 n と s が共に 0 のとき入...
[ { "submission_id": "aoj_0030_7937516", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int lli;\nint n, s;\nbool used[10];\nlli dfs(bool used[10], int now, int sum) {\n if (sum > s)\n return 0;\n if (now == n) {\n if (sum == s)\n return 1;\n return 0;\n }\...
aoj_NTL_2_C_cpp
Multiplication of Big Integers Given two integers $A$ and $B$, compute the product, $A \times B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the product in a line. Constraints $-1 \times 10^{1000} \leq A, B \leq 10^{1000}$ Sample Input 1 5 8 Sample Output 1 40 Sample...
[ { "submission_id": "aoj_NTL_2_C_10940298", "code_snippet": "#include<iostream>\n#include<string>\nusing namespace std;\n\nstring fixedNum( string a )\n{\n if( a.size() == 1 )\n return a;\n for( int i = 0; i < a.size(); i++ )\n if( '1'<= a[i] && a[i] <= '9' )\n return a.substr(...
aoj_0044_cpp
素数 II 素数というのは、1 よりも大きくそれ自身か 1 でしか割りきれない整数をいいます。例えば、2 は、2 と 1 でしか割り切れないので素数ですが、12 は、12 と 1 のほかに、2, 3, 4, 6 で割りきれる数なので素数ではありません。 整数 n を入力したとき、 n より小さい素数のうち最も大きいものと、 n より大きい素数のうち最も小さいものを出力するプログラムを作成してください。 Input 複数のデータセットが与えられます。各データセットに n (3 ≤ n ≤ 50,000) が1行に与えられます。 データセットの数は 50 を超えません。 Output 各データセットに対して、 n より小さい素数のうち最...
[ { "submission_id": "aoj_0044_3570869", "code_snippet": "#include <cstdio>\n#include <algorithm>\n#include <iostream>\n#include <vector>\n#include <string.h>\n#include <math.h>\n#include <time.h>\n#include <stdlib.h>\nusing namespace std;\n\n\n\nint main(){\n\tint d,arr[100000],count,ch;\n\tarr[0]=2;\n\tcoun...
aoj_0040_cpp
アフィン暗号 簡単な暗号法の一つに、アフィン暗号というものがあります。まず、アルファベット a〜z を a = 0, b = 1, c = 2,..., x = 23, y = 24, z = 25 と 0〜25 の数字に置き換えます。そして、以下の式で、原文のアルファベットを置換します。 $F(\gamma) = (\alpha \cdot \gamma + \beta)$ mod $26$ ただし、mod 26 は 26 で割った余りを表します。例えば、$\alpha = 3, \beta = 2$ のとき、アルファベットの 'a' (=0) は、$F(0) = (3 \cdot 0 + 2)$ mod $26 = 2$ で ...
[ { "submission_id": "aoj_0040_2489714", "code_snippet": "#include<iostream>\n#include<string>\n#include<cmath>\n#include<queue>\n#include<map>\n#include<set>\n#include<list>\n#include<iomanip>\n#include<vector>\n#include<functional>\n#include<algorithm>\n#include<cstdio>\n#include<unordered_map>\nusing names...
aoj_0042_cpp
泥棒 宝物がたくさん収蔵されている博物館に、泥棒が大きな風呂敷を一つだけ持って忍び込みました。盗み出したいものはたくさんありますが、風呂敷が耐えられる重さが限られており、これを超えると風呂敷が破れてしまいます。そこで泥棒は、用意した風呂敷を破らず且つ最も価値が高くなるようなお宝の組み合わせを考えなくてはなりません。 風呂敷が耐えられる重さ W 、および博物館にある個々のお宝の価値と重さを読み込んで、重さの総和が W を超えない範囲で価値の総和が最大になるときの、お宝の価値総和と重さの総和を出力するプログラムを作成してください。ただし、価値の総和が最大になる組み合わせが複数あるときは、重さの総和が小さいものを出力することとします。 I...
[ { "submission_id": "aoj_0042_7370385", "code_snippet": "#include <bits/stdc++.h>\n#include <stdint.h>\n\nusing namespace std;\n\n#define PI M_PI\n#define MOD 1000000007\n#define debug(x) cout << #x << \" = \" << x << endl\n#define MAP_HAS_KEY(m, key) (m.find(key) != m.end())\n\ntemplate<class T> std::vector...
aoj_0041_cpp
式 与えられた 4 つの 1 から 9 の整数を使って、答えが 10 になる式をつくります。 4 つの整数 a, b, c, d を入力したとき、下記の条件に従い、答えが 10 になる式を出力するプログラムを作成してください。また、答えが複数ある時は、最初に見つかった答えだけを出力するものとします。答えがない時は、0 と出力してください。 演算子として、加算 (+)、減算 (-)、乗算 (*) だけを使います。除算 (/) は使いません。使用できる演算子は3個です。 数を4つとも使わなければいけません。 4つの数の順番は自由に入れ換えてかまいません。 カッコを使ってもかまいません。使用できるカッコは3組(6個)以下です。 Inpu...
[ { "submission_id": "aoj_0041_8027424", "code_snippet": "#pragma region Macros\n\n// #pragma GCC optimize(\"O3,unroll-loops\")\n// #pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2\")\n\n#include <bits/extc++.h>\n// #include <atcoder/all>\n// using namespace atcoder;\nusing namespace std;\nu...
aoj_0067_cpp
島の数 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ ...
[ { "submission_id": "aoj_0067_5246731", "code_snippet": "#include <bits/stdc++.h>\n#define NIL (-1)\n#define LL long long\nusing namespace std;\nconst int64_t MOD = 1e9 + 7;\nconst int INF = INT_MAX;\nconst double PI = acos(-1.0);\n\nvector<string> island(12);\nvector<vector<bool>> seen(12, vector<bool>(12))...
aoj_0043_cpp
パズル 1 〜 9 の数字を 14 個組み合わせて完成させるパズルがあります。与えられた 13 個の数字にもうひとつ数字を付け加えて完成させます。 パズルの完成条件は 同じ数字を2つ組み合わせたものが必ずひとつ必要です。 残りの12 個の数字は、3個の数字の組み合わせ4つです。 3個の数字の組み合わせ方は、同じ数字を3つ組み合わせたものか、または3つの連続する数字を組み合わせたものです。ただし、9 1 2 のような並びは連続する数字とは認められません。 同じ数字は4 回まで使えます。 13 個の数字からなる文字列を読み込んで、パズルを完成することができる数字を昇順に全て出力するプログラムを作成してください。なお、1〜9 のどの数字を...
[ { "submission_id": "aoj_0043_4893249", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef vector<ll> vl;\n#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)\n#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_le...
aoj_0072_cpp
灯篭 会津若松市は「歴史の町」として知られています。今から約 400 年前、蒲生氏郷により城下町の骨格が作られましたが、その後、徳川三代将軍家光公の異母弟「保科正之」公を藩祖とする会津藩 23 万石の中心都市として発展しました。今でも市内のいたるところに史跡や昔日の面影が残っているため、毎年、全国から多くの観光客が訪れています。 今年は、NHK大河ドラマで「新選組!」が放送されているため、新選組ゆかりの地(*1)として、大幅に観光客が増加しています。そこで市では、市内に点在する史跡を結ぶ通り沿いに 100 m 間隔で灯篭を設置して飾りたてることにしました。灯篭を飾ってある通りを辿れば市内の全ての史跡に到達できるように設置することが条...
[ { "submission_id": "aoj_0072_1759212", "code_snippet": "// 0072\n#include <iostream>\n#include <vector>\n#include <stdio.h>\n#include <stdlib.h>\nusing namespace std;\n\nstruct road{\n\tint dis;\n\tint v1;\n\tint v2;\n};\n\n\nint findSet(int x, vector<int> &p){\n\tif(x != p[x])\n\t\tp[x] = findSet(p[x], p);...
aoj_0056_cpp
ゴールドバッハの予想 4 以上の偶数は 2 つの素数の和で表すことができるということが知られています。これはゴールドバッハ予想といい、コンピュータの計算によりかなり大きな数まで正しいことが確かめられています。例えば、10 は、7 + 3、5 + 5 の 2 通りの素数の和で表すことができます。 整数 n を入力し、 n を 2 つの素数の和で表す組み合わせ数が何通りあるかを出力するプログラムを作成してください。ただし、 n は 4 以上、50,000 以下とします。また、入力される n は偶数であるとはかぎりません。 Input 複数のデータセットが与えられます。各データセットに n が1行に与えられます。 n が 0 のとき入力の...
[ { "submission_id": "aoj_0056_9629737", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint main(void){\n vector<int> yakusu(50001, -1);\n for(int i=2; i<=50000; i++){\n if(yakusu[i]!=-1) continue;\n int copy=i;\n while(copy<=50000){\n if(yakusu[copy]==-1) yakusu[copy]=i;\n ...
aoj_0088_cpp
博士が愛した符号 博士 : ピーター君、ついにやったよ。 ピーター : どうしました、デビッド博士?またくだらない発明ですか? 博士 : この表だよ、この表。 文字 符号 (空白) 101 ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 文字 符号 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 文字 符号 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 文字 符号 S 001...
[ { "submission_id": "aoj_0088_1907220", "code_snippet": "#include<iostream>\n#include<string>\nusing namespace std;\nstring c2s(char c){\n if(c==' ') return \"101\";\n if(c=='\\'') return \"000000\";\n if(c==',') return \"000011\";\n if(c=='-') return \"10010001\";\n if(c=='.') return \"010001\";\n if(...