description
stringlengths
29
13k
solution
listlengths
0
16.3k
Ramu’s uncle has left him a stable in his Will. But the stable is not in a good condition. The roofs leak and need to be repaired. There are a number of stalls in the stable. A stall may or may not contain a horse. Ramu has to buy new cement sheets to cover these stalls. He has to cover atleast all those stalls that h...
[ "# /he/uncle's-will\n\nno_of_tc = input()\nfor tc in range(no_of_tc) :\n\tline = raw_input()\n\tmax_sheets = int(line.split(' ')[0])\n\ttotal_stalls = int(line.split(' ')[1])\n\tfilled_stalls = int(line.split(' ')[2])\n\tstall_map = [False] * total_stalls\n\tfor i in range(filled_stalls) :\tstall_map[input() - 1] =...
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
[ "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.InputMismatchException;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.stream.LongStrea...
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
[ "X, Y, Z = map(int,input().split())\n\nprint(Z, X, Y)", "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n\tll a,b,c;\n\tcin>>a>>b>>c;\n\tcout<<c<<\" \"<<a<<\" \"<<b;\t\n}", "#include<iostream>\nusing namespace std;\nint main(){\n int a, b, c;\n cin >> a >> b >> c;\n cout ...
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
[ "t = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nx = t[0] * (a[0] - b[0])\ny = x + t[1] * (a[1] - b[1])\nif x*y > 0:\n\tprint(0)\nelif x*y == 0:\n\tprint('infinity')\nelif abs(x) % abs(y) == 0:\n\tprint(2 * (abs(x) // abs(y)))\nelse:\n\tprint(2 * (abs...
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
[ "l,r = map(int,input().split())\nr = min(r, l+4038)\nans = 2018\nfor i in range(l,r):\n for j in range(l+1,r+1):\n if ans > i*j%2019:\n ans = i*j%2019\nprint(ans)", "import java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System...
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
[ "#include <bits/stdc++.h>\nint main() {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n if (b % a == 0) printf(\"%d\\n\", a+b);\n else printf(\"%d\\n\", b-a);\n}", "a,b = list(map(int,input().split()))\nprint(a+b if b%a == 0 else b-a)\n", "a, b = (int(i) for i in input().split())\nprint(a+b) if b%a == 0 else print...
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
[ "#解説参照\nl=int(input())\nr=0\nwhile 2**(r+1)<=l:\n r+=1\nn=r+1\nans=[]\nfor i in range(r):\n ans.append((i+1,i+2,0))\n ans.append((i+1,i+2,2**i))\n\nfor t in range(n-1,0,-1):\n if l-2**(t-1)>=2**r:\n ans.append((t,n,l-2**(t-1)))\n l-=2**(t-1)\nprint(n,len(ans))\nfor a in ans:\n print(*a)...
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
[ "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n HashMap<String,Long> namelist = new HashMap<>();\n String s = \"MARCH\";\n for(int i = 0;i<s....
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
[ "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<cmath>\n#include<cstdlib>\n#include<algorithm>\n#include<set>\nusing namespace std;\n#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)\n#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)\nmultiset<string>s;\nmultiset<string>::itera...
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
[ "n=int(input())\na=list(map(int,input().split()))\nu=0\ns=1\nx=0\ny=0\nfor i in a:\n u+=i\n if s*u<=0:\n x+=1-s*u\n u=s\n s=s*(-1)\ns=-1\nu=0\nfor i in a:\n u+=i\n if s*u<=0:\n y+=1-s*u\n u=s\n s=-1*s\nprint(min(x,y))", "#include<iostream>\n#include<vector>\n#include<algorith...
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneou...
[ "import java.io.IOException; \nimport java.io.InputStream; \nimport java.io.PrintWriter; \nimport java.util.*; \n \n\nclass Main{ \n\n\tstatic void solve(){\n\t\tint x = ni();\n\t\tdouble p = ni()/100.0;\n\t\tdouble ans = 0;\n\t\tif(x%2==0)ans=(double)x/(2*p);\n\t\telse{\n\t\t\tans=1;\n\t\t\tans += (x-1)/2;\n\t\t\t...
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
[ "#encoding=utf-8\n\ninp = input()\nx = 100000\nfor i in xrange(inp):\n\tx = x * 1.05\n\tif int(x % 1000) != 0:\n\t\tx += 1000 - int(x % 1000)\n\nprint int(x)", "import math\nn = int(input())\na = 100000\nfor _ in range(n):\n a *= 1.05\n a = 1000 * math.ceil(a / 1000)\nprint(a)\n\n", "n=int(raw_input())\ng...
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends w...
[ "#include<iostream>\n#include<regex>\n#include<string>\n\nint main()\n{\n\tint n;\n\tstd::cin >> n;\n\tstd::cin.ignore();\n\n\twhile( n-- )\n\t{\n\t\tstd::string s;\n\t\tstd::getline( std::cin, s );\n\n\t\tstd::smatch m;\n\t\tif( std::regex_match( s, m, std::regex( \">\\'(=+)#(=+)~\" ) ) && m[1].length() == m[2].le...
Today is the ticket release date for Aizu Entertainment's recommended idol group "Akabeko & Koboushi". There are four types of tickets: S seat 6000 yen A seat 4000 yen B seat 3000 yen C seat 2000 yen You, the sales manager, are excitedly waiting for the launch. Finally on sale. It's selling very well! Shortly after ...
[ "for i in range(4):\n t,n=map(int,input().split())\n if t==1:\n print(f'{6000*n}')\n elif t==2:\n print(f'{4000*n}')\n elif t==3:\n print(f'{3000*n}')\n elif t==4:\n print(f'{2000*n}')\n", "#include <stdio.h>\nint main(void){\n\tint t,n;\n\tint i;\n\t\n\tfor(i=0;i<4;i++)...
problem In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions. * The Bingo card is divided into squares of N rows and N columns, and one posi...
[ "#include<cstdio>\n#include<cstring>\n#include<iostream>\n#include<vector>\n#include<algorithm>\n#include<string>\nusing namespace std;\nint N,M,S;\nint dp[2][50][3001];\n#define AMA (100000)\nint solve(){\n memset(dp,0,sizeof(dp));\n int now;\n int next;\n int ret = 0;\n dp[1][0][0]=1;\n for(int m=1;m<=M;m++...
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future. Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as...
[ "#include <bits/stdc++.h>\nusing namespace std;\n\n#define dump(...) cout<<\"# \"<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl\n#define repi(i,a,b) for(int i=int(a);i<int(b);i++)\n#define peri(i,a,b) for(int i=int(b);i-->int(a);)\n#define rep(i,n) repi(i,0,n)\n#define per(i,n) peri(i,0,n)\n#define all(c) begin(c),end(c)...
A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more about keyword search algorithms. Fo...
[ "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic int[] key = new int[256];\n\n\tpublic static void main(String[] args) {\n\t\twhile (true) {\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (true) {\n\t\t\t\tString line...
Example Input 10 3 3 7 8 9 2 5 Output 23
[ "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint main(){\n\tint n,m;\n\tcin >> n >> m;\n\tvector<int> after(n+2, 0);\n\tfor(int i=0; i<m; i++){\n\t\tint c,d;\n\t\tcin >> c >> d;\n\t\tafter[c] = max(after[c], d);\n\t}\n\tint ans = 0;\n\tint farthest = 0;\n\tfor(int i=0; i<=n...
Problem N idols, numbered from 1 to n in order, are lined up in a row. Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1. At time 0, m idols with numbers a1, a2, ..., am have secret i...
[ "#include<iostream>\n#include<vector>\n#include<string>\n#include<algorithm>\n#include<map>\n#include<set>\n#include<utility>\n#include<cmath>\n#include<cstring>\n#include<queue>\n#include<cstdio>\n#define loop(i,a,b) for(int i=a;i<b;i++) \n#define rep(i,a) loop(i,0,a)\n#define pb push_back\n#define mp make_pair\n#...
Grated radish (daikon-oroshi) is one of the essential spices in Japanese cuisine. As the name shows, it’s made by grating white radish. You are developing an automated robot for grating radish. You have finally finished developing mechan- ical modules that grates radish according to given instructions from the microco...
[ "#include <stdio.h>\n#include <math.h>\n#include <iostream>\n#include <complex>\n#include <vector>\n#include <utility>\n#include <algorithm>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\n#define mp make_pair\nconst double EPS = 1e-12;\nconst double pi = atan2(0.0, -1.0);\ntypedef comp...
The jewel, a national treasure of the Kingdom of Pal, was stolen by bandits. As an adventurer, you heard the rumor and headed for the thief's hideout and managed to get the jewels back. However, when I went to return the jewel to the castle of the Kingdom of Pal, the guard of the castle said, "My king has not complete...
[ "#include<iostream>\n#include<string>\n#include<queue>\n#include<algorithm>\n#include<set>\nusing namespace std;\n#define rep(i,n) for ( int i = 0; i < n; i++)\nstatic const int MAX = 50;\nstatic const int PMAX = 11;\nstatic const string DT = \"URDL\";\nstatic const int di[4] = {-1, 0, 1, 0};\nstatic const int dj[4...
Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square. She is...
[ "#include <iostream>\n#include <iomanip>\n#include <sstream>\n#include <cstdio>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <complex>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <cassert>\n#include <climits>\n#include <queue>\n#include <set>\n#include <map>\n#includ...
I-σ A permutation of magnitude N is a sequence of elements in a sequence (1, 2, 3,…, N). For example, (5, 2, 1, 4, 3) is a permutation of size 5, while (1, 5, 1, 2, 3) is not. This problem is a reactive task. You play a response program and a "permutation guessing game". First of all, the response program internally ...
[ "#include<stdio.h>\n#include<algorithm>\nusing namespace std;\nint p[500];\nint q[250][500];\nint r[250][500];\nint ret[500];\nint s[500];\nint t[250][500];\nint u[500];\nint v[250][500];\nint w[250][500];\nint ABS(int a){return max(a,-a);}\nint LIM=240;\nint main(){\n\tint a;\n\tscanf(\"%d\",&a);\n\tfor(int i=0;i<...
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in...
[ "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VI = vector<int>;\nusing VVI = vector<VI>;\nusing PII = pair<int, int>;\nusing LL = long long;\nusing VL = vector<LL>;\nusing VVL = vector<VL>;\nusing PLL = pair<LL, LL>;\nusing VS = vector<string>;\n\n#define ALL(a) begin((a)),end((a))\n#define RALL(a) (a)....
G: Almost Infinite Glico problem There is a field where N squares are arranged in a ring. The i-th (1 \ leq i \ leq N-1) cell is ahead of the i + 1th cell. However, if i = N, the next cell is the first cell. The first cell you are in is the first cell. From there, play rock-paper-scissors K times in a row according ...
[ "#include<bits/stdc++.h>\nusing namespace std;\n\n// macro\n#define rep(i,n) for(i=0;i<n;i++)\n#define ll long long\n#define all(v) v.begin(), v.end()\n\n// code starts\n#define MOD 1000000007\n\nint main()\n{\n ll n,m,k;cin>>n>>m>>k;\n vector<int> p(m);\n ll i,j,l;\n rep(i,m)cin>>p[i];\n ll num=1;\n ll needs...
F: Invariant Tree Problem Statement You have a permutation p_1, p_2, ... , p_N of integers from 1 to N. You also have vertices numbered 1 through N. Find the number of trees while satisfying the following condition. Here, two trees T and T' are different if and only if there is a pair of vertices where T has an edge ...
[ "#include<bits/stdc++.h>\n\n#define pb push_back\n#define mp make_pair\n#define fi first\n#define se second\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair<int,int> pii;\ntypedef pair<ll,ll> pll;\n\ntemplate <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false...
test UnionFind(バイナリ入力) Example Input Output
[ "#include <algorithm>\n#include <cassert>\n#include <cstdio>\n#include <iostream>\n#include <limits>\n#include <random>\n#include <utility>\n#include <vector>\n\nnamespace procon {\nclass UnionFind {\nprivate:\n struct nodeinfo {\n int par;\n int rank;\n nodeinfo(int par) : par(par), rank(0) {}\n };\n s...
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
[ "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct SuccessiveShortestPath {\n struct Edge{ int to, cap, cost, rev; };\n int n, init;\n vector<vector<Edge>> g;\n vector<int> dist, pv, pe, h;\n\n SuccessiveShortestPath() {}\n SuccessiveShortestPath(int n, int INF = 1e9)\n : n(n), g(n), init(INF), dist...