id
stringlengths
6
117
description
stringlengths
29
13k
code
stringlengths
9
465k
language
class label
4 classes
test_samples
dict
source
class label
5 classes
p03031 AtCoder Beginner Contest 128 - Switches_2000
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How ...
#abc128c n,m=map(int,raw_input().split()) s=[map(int,raw_input().split()) for i in range(m)] p=map(int,raw_input().split()) res=0 for i in range(2**n): res+=1 for j in range(len(s)): on=0 for k in range(s[j][0]): on+=((i>>(s[j][k+1]-1))%2) if on%2!=p[j]: res-=1 break print res
1Python2
{ "input": [ "2 2\n2 1 2\n1 2\n0 1", "5 2\n3 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 1", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "5 2\n1 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 -1", "4 0\n1 1 2\n1 2\n0 1", "1 0\n0 1 4\n1 1\n0 1\n0 0 -1", "9 2\n3 1 2 5\n2 2...
5ATCODER
p03031 AtCoder Beginner Contest 128 - Switches_2001
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How ...
#include<iostream> using namespace std; int N_MAX = 10; int main() { int n,nn,m,i,j,kk,t,res=0; int k[N_MAX],s[N_MAX][N_MAX],p[N_MAX],ss[N_MAX]; cin >> n >> m; for(i=0;i<m;i++){ cin >> k[i]; for(j=0;j<k[i];j++) cin >> s[i][j]; } for(i=0;i<m;i++) cin >> p[i]; nn=1<<n; for(i=0;i<nn;i++){...
2C++
{ "input": [ "2 2\n2 1 2\n1 2\n0 1", "5 2\n3 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 1", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "5 2\n1 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 -1", "4 0\n1 1 2\n1 2\n0 1", "1 0\n0 1 4\n1 1\n0 1\n0 0 -1", "9 2\n3 1 2 5\n2 2...
5ATCODER
p03031 AtCoder Beginner Contest 128 - Switches_2002
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How ...
N,M = map(int,input().split()) S = [[int(i)-1 for i in input().split()] for _ in range(M)] P = [int(i) for i in input().split()] ans = 0 for i in range(1<<N): for j in range(M): cnt = 0 for s in S[j][1:]: if i >> s & 1: cnt += 1 if cnt%2 != P[j]: break else: ans += 1...
3Python3
{ "input": [ "2 2\n2 1 2\n1 2\n0 1", "5 2\n3 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 1", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "5 2\n1 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 -1", "4 0\n1 1 2\n1 2\n0 1", "1 0\n0 1 4\n1 1\n0 1\n0 0 -1", "9 2\n3 1 2 5\n2 2...
5ATCODER
p03031 AtCoder Beginner Contest 128 - Switches_2003
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How ...
import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] nm = br.readLine().split(" "); int n = Integer.parseInt(nm[0]); int m = Integer.parseInt(nm[1]); String[] ...
4JAVA
{ "input": [ "2 2\n2 1 2\n1 2\n0 1", "5 2\n3 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 1", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "5 2\n1 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 -1", "4 0\n1 1 2\n1 2\n0 1", "1 0\n0 1 4\n1 1\n0 1\n0 0 -1", "9 2\n3 1 2 5\n2 2...
5ATCODER
p03172 Educational DP Contest - Candies_2004
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two way...
# -*- coding: utf-8 -*- import sys N,K=map(int, sys.stdin.readline().split()) A=map(int, sys.stdin.readline().split()) mod=10**9+7 T=[1] for a in A: W=[0] #WA:累積和 l=len(T) for j,x in enumerate(T): if j==0: W.append( x%mod ) else: W.append( (W[-1]+x)%mod ) T=[] #Temporary for k in range( min (K+1,a+l) ):...
1Python2
{ "input": [ "2 0\n0 0", "1 10\n9", "4 100000\n100000 100000 100000 100000", "3 4\n1 2 3", "1 10\n17", "4 100000\n101000 100000 100000 100000", "1 10\n3", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000", "4 100100\n101000 100000 100100 101000", ...
5ATCODER
p03172 Educational DP Contest - Candies_2005
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two way...
#include<bits/stdc++.h> using namespace std; const int N = 110,mod=1e9+7; typedef long long ll; int a[N]; ll s[110000]; ll f[110][110000]; int main() { ll n,k; cin>>n>>k; memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) cin>>a[i]; for(int i =0;i<=k;i++) f[1][i] = (i<=a[1])? 1:0; for(int i=2;i<=n;i++) { memset...
2C++
{ "input": [ "2 0\n0 0", "1 10\n9", "4 100000\n100000 100000 100000 100000", "3 4\n1 2 3", "1 10\n17", "4 100000\n101000 100000 100000 100000", "1 10\n3", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000", "4 100100\n101000 100000 100100 101000", ...
5ATCODER
p03172 Educational DP Contest - Candies_2006
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two way...
mod = 10**9+7 def comb(a,b): return fact[a]*inv[b]*inv[a-b]%mod n,k = map(int, input().split()) a = list(map(int, input().split())) fact = [1] for i in range(n+k): fact.append(fact[-1]*(i+1)%mod) inv = [1]*(n+k+1) inv[n+k] = pow(fact[n+k],mod-2,mod) for i in range(n+k)[::-1]: inv[i] = inv[i+1]*(i+1)%m...
3Python3
{ "input": [ "2 0\n0 0", "1 10\n9", "4 100000\n100000 100000 100000 100000", "3 4\n1 2 3", "1 10\n17", "4 100000\n101000 100000 100000 100000", "1 10\n3", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000", "4 100100\n101000 100000 100100 101000", ...
5ATCODER
p03172 Educational DP Contest - Candies_2007
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two way...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
4JAVA
{ "input": [ "2 0\n0 0", "1 10\n9", "4 100000\n100000 100000 100000 100000", "3 4\n1 2 3", "1 10\n17", "4 100000\n101000 100000 100000 100000", "1 10\n3", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000", "4 100100\n101000 100000 100100 101000", ...
5ATCODER
p03318 AtCoder Beginner Contest 101 - Snuke Numbers_2008
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
""" A = [] def S(x): return sum(map(int, str(x))) def f(d, a, s): global A if d>=20: return True if s==0: t = int("9"*len(str(a))) if a*S(t)<=t*S(a): if a<=10**15: A += [a] return True else: return False for i in range(min(s, 9)+1)[::-1]: if not f(d+1, a+i*10**d...
1Python2
{ "input": [ "10", "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", ...
5ATCODER
p03318 AtCoder Beginner Contest 101 - Snuke Numbers_2009
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
#include <iostream> #include <vector> #include <algorithm> using namespace std; long long f(long long n) { long long res = 0; while (n > 0) { res += n%10; n /= 10; } return res; } double g(long long n) { return (double)(n)/f(n); } int main() { vector<long long> res; long long base = 1; for (i...
2C++
{ "input": [ "10", "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", ...
5ATCODER
p03318 AtCoder Beginner Contest 101 - Snuke Numbers_2010
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
import math def next_sunuke(N): D = math.ceil(math.log(N,10) + 1) z = str(N) zx = [int(z[:1]) for z in z] Z = N / sum(zx) ret_val = N # print(Z) ret_vals = [ret_val] for d in range(0, D): x = ( (10 ** (d + 1)) * math.floor((N / (10 ** (d+1))) + 1 ) ) - 1 # print(x) ...
3Python3
{ "input": [ "10", "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", ...
5ATCODER
p03318 AtCoder Beginner Contest 101 - Snuke Numbers_2011
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long sunukeNum = 1; for(int i=0;i<n;i++){ String sunukeString = "" + sunukeNum; double min = Double.MAX_VALUE; long sunukecand = 0; for(int j=0...
4JAVA
{ "input": [ "10", "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", ...
5ATCODER
p03474 AtCoder Beginner Contest 084 - Postal Code_2012
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. Constraints * 1≤A,B≤5 * |S|=A+B+1 * S consists of `-` and di...
A,B = map(int,raw_input().split()) S = raw_input() data = [str(i) for i in range(10)] mozi = 'Yes' if S[A] == '-': for i in range(A+B+1): if i == A: continue if S[i] not in data: mozi = 'No' else: mozi = 'No' print mozi
1Python2
{ "input": [ "1 2\n7444", "3 4\n269-6650", "1 1\n---", "2 2\n7444", "6 4\n269-6650", "1 2\n---", "0 2\n7444", "6 8\n269-6650", "1 0\n---", "0 2\n5343", "6 1\n269-6650", "1 0\n-,-", "0 1\n5343", "6 2\n269-6650", "1 0\n-+-", "-1 1\n5343", "6 2\n0566-96...
5ATCODER
p03474 AtCoder Beginner Contest 084 - Postal Code_2013
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. Constraints * 1≤A,B≤5 * |S|=A+B+1 * S consists of `-` and di...
#include <bits/stdc++.h> using namespace std; int main() { int a,b,i,j,n,cur=1; cin >> a >> b; string s; cin >> s; for(i=0; i<a+b+1; i++){ if((i!=a && s[i]=='-')||(i==a && s[i]!='-')){ cout << "No"; return 0; } } cout << "Yes"; }
2C++
{ "input": [ "1 2\n7444", "3 4\n269-6650", "1 1\n---", "2 2\n7444", "6 4\n269-6650", "1 2\n---", "0 2\n7444", "6 8\n269-6650", "1 0\n---", "0 2\n5343", "6 1\n269-6650", "1 0\n-,-", "0 1\n5343", "6 2\n269-6650", "1 0\n-+-", "-1 1\n5343", "6 2\n0566-96...
5ATCODER
p03474 AtCoder Beginner Contest 084 - Postal Code_2014
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. Constraints * 1≤A,B≤5 * |S|=A+B+1 * S consists of `-` and di...
a, b = map(int, input().split()) s = input() t = s.split('-') print('Yes' if s[a] == '-' and len(t) == 2 else 'No')
3Python3
{ "input": [ "1 2\n7444", "3 4\n269-6650", "1 1\n---", "2 2\n7444", "6 4\n269-6650", "1 2\n---", "0 2\n7444", "6 8\n269-6650", "1 0\n---", "0 2\n5343", "6 1\n269-6650", "1 0\n-,-", "0 1\n5343", "6 2\n269-6650", "1 0\n-+-", "-1 1\n5343", "6 2\n0566-96...
5ATCODER
p03474 AtCoder Beginner Contest 084 - Postal Code_2015
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. Constraints * 1≤A,B≤5 * |S|=A+B+1 * S consists of `-` and di...
import java.util.*; public class Main { Scanner in = new Scanner(System.in); public void run() { int a = in.nextInt(), b = in.nextInt(); String s = in.next(); boolean ok = true; for (int i = 0; i <= a + b; i++) { if (i == a) { ok &= s.charAt(i) == '...
4JAVA
{ "input": [ "1 2\n7444", "3 4\n269-6650", "1 1\n---", "2 2\n7444", "6 4\n269-6650", "1 2\n---", "0 2\n7444", "6 8\n269-6650", "1 0\n---", "0 2\n5343", "6 1\n269-6650", "1 0\n-,-", "0 1\n5343", "6 2\n269-6650", "1 0\n-+-", "-1 1\n5343", "6 2\n0566-96...
5ATCODER
p03637 AtCoder Beginner Contest 069 - 4-adjacent_2016
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ...
# -*- coding: utf-8 -*- N = int(raw_input()) a = map(int, raw_input().split()) def is_odd(n): return True if (n%2!=0) else False def is_s_even(n): return True if (n%4!=0 and n%2==0) else False def is_w_even(n): return True if (n%4==0) else False # 奇数配列p[] 4の倍数配列r[] どちらもない配列q[] p, q, r = [], [], [] for ...
1Python2
{ "input": [ "6\n2 7 1 8 2 8", "3\n1 4 1", "3\n1 10 100", "2\n1 1", "4\n1 2 3 4", "6\n2 7 2 8 2 8", "3\n-1 1 1", "3\n0 4 1", "3\n2 10 100", "4\n2 2 3 4", "6\n4 7 2 8 2 8", "3\n0 1 1", "3\n0 10 100", "4\n0 2 3 4", "6\n6 7 2 8 2 8", "3\n0 11 100", "4\n...
5ATCODER
p03637 AtCoder Beginner Contest 069 - 4-adjacent_2017
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ...
#include<iostream> using namespace std; int n,s,x,y,z; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>s; if(s%4==0)x++; else if(s%2==0)y++; else z++; } if(x>=z)cout<<"Yes"<<"\n"; else if(z-x==1 and y==0)cout<<"Yes"<<"\n"; else cout<<"No"<<"\n"; }
2C++
{ "input": [ "6\n2 7 1 8 2 8", "3\n1 4 1", "3\n1 10 100", "2\n1 1", "4\n1 2 3 4", "6\n2 7 2 8 2 8", "3\n-1 1 1", "3\n0 4 1", "3\n2 10 100", "4\n2 2 3 4", "6\n4 7 2 8 2 8", "3\n0 1 1", "3\n0 10 100", "4\n0 2 3 4", "6\n6 7 2 8 2 8", "3\n0 11 100", "4\n...
5ATCODER
p03637 AtCoder Beginner Contest 069 - 4-adjacent_2018
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ...
N=int(input()) a=list(map(int,input().split())) odd=0 m2=0 m4=0 for n in a: if n%2==1: odd+=1 elif n%4!=0: m2+=1 else: m4+=1 if m4>=odd or (m2==0 and m4>=odd-1): print('Yes') else: print('No')
3Python3
{ "input": [ "6\n2 7 1 8 2 8", "3\n1 4 1", "3\n1 10 100", "2\n1 1", "4\n1 2 3 4", "6\n2 7 2 8 2 8", "3\n-1 1 1", "3\n0 4 1", "3\n2 10 100", "4\n2 2 3 4", "6\n4 7 2 8 2 8", "3\n0 1 1", "3\n0 10 100", "4\n0 2 3 4", "6\n6 7 2 8 2 8", "3\n0 11 100", "4\n...
5ATCODER
p03637 AtCoder Beginner Contest 069 - 4-adjacent_2019
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ...
import java.util.*; import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.Math.*; import static java.lang.System.*; import java.io.PrintWriter; public class Main { public static void main(String[] args) { int i=0,j=0,k=0; Scanner sc = new Scanner(in); int n = parseInt(sc.ne...
4JAVA
{ "input": [ "6\n2 7 1 8 2 8", "3\n1 4 1", "3\n1 10 100", "2\n1 1", "4\n1 2 3 4", "6\n2 7 2 8 2 8", "3\n-1 1 1", "3\n0 4 1", "3\n2 10 100", "4\n2 2 3 4", "6\n4 7 2 8 2 8", "3\n0 1 1", "3\n0 10 100", "4\n0 2 3 4", "6\n6 7 2 8 2 8", "3\n0 11 100", "4\n...
5ATCODER
p03794 Mujin Programming Challenge 2017 - Oriented Tree_2020
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.) For a fixed T', we will define d(s,\ t) fo...
#include <cstdio> #include <cctype> #include <cstring> #include <algorithm> #include <vector> #define debug(...) fprintf(stderr, __VA_ARGS__) #ifndef AT_HOME #define getchar() IO::myGetchar() #define putchar(x) IO::myPutchar(x) #endif namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline cha...
2C++
{ "input": [ "4\n1 2\n2 3\n3 4", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n1 4", "6\n1 2\n1 3\n1 4\n2 5\n2 6", "10\n2 4\n2 5\n1 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n2 4", "10\n2 4\n2 5\n1 3\n3 7\n1 6\n2 8\n9 5\n8 6\n10 6", "10\n2 4\n2 5\n8 3\n10 7\...
5ATCODER
p03794 Mujin Programming Challenge 2017 - Oriented Tree_2021
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.) For a fixed T', we will define d(s,\ t) fo...
# doc: git.io/vy4co def graph(inp): nodes = dict() N = None for line in inp.splitlines(): if N is None: N = int(line.strip()) for k in range(1, N + 1): nodes[k] = set() continue i, k = map(int, line.split()) nodes[i].add(k) ...
3Python3
{ "input": [ "4\n1 2\n2 3\n3 4", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n1 4", "6\n1 2\n1 3\n1 4\n2 5\n2 6", "10\n2 4\n2 5\n1 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n2 4", "10\n2 4\n2 5\n1 3\n3 7\n1 6\n2 8\n9 5\n8 6\n10 6", "10\n2 4\n2 5\n8 3\n10 7\...
5ATCODER
p03794 Mujin Programming Challenge 2017 - Oriented Tree_2022
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.) For a fixed T', we will define d(s,\ t) fo...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; imp...
4JAVA
{ "input": [ "4\n1 2\n2 3\n3 4", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n1 4", "6\n1 2\n1 3\n1 4\n2 5\n2 6", "10\n2 4\n2 5\n1 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n2 4", "10\n2 4\n2 5\n1 3\n3 7\n1 6\n2 8\n9 5\n8 6\n10 6", "10\n2 4\n2 5\n8 3\n10 7\...
5ATCODER
p03963 AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer_2023
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints * 1≦N≦1000 * 2≦K≦1000 * The correct answer i...
input_line = map(int,raw_input().split(" ")) N = input_line[0] K = input_line[1] A = K * pow(K-1,N-1) print A
1Python2
{ "input": [ "2 2", "1 10", "1 2", "1 1", "1 4", "1 8", "0 8", "0 13", "0 7", "0 12", "1 12", "1 3", "0 3", "0 0", "0 -1", "1 -1", "1 0", "-1 -1", "-2 -1", "-3 -1", "-3 0", "1 -2", "2 3", "0 -2", "0 4", "2 8", ...
5ATCODER
p03963 AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer_2024
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints * 1≦N≦1000 * 2≦K≦1000 * The correct answer i...
#include <iostream> using namespace std; int main() { int a,b,m; cin>>a>>b; m=b; for(int i=1;i<=a-1;i++) { b*=(m-1); } cout<<b; return 0; }
2C++
{ "input": [ "2 2", "1 10", "1 2", "1 1", "1 4", "1 8", "0 8", "0 13", "0 7", "0 12", "1 12", "1 3", "0 3", "0 0", "0 -1", "1 -1", "1 0", "-1 -1", "-2 -1", "-3 -1", "-3 0", "1 -2", "2 3", "0 -2", "0 4", "2 8", ...
5ATCODER
p03963 AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer_2025
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints * 1≦N≦1000 * 2≦K≦1000 * The correct answer i...
a, b = [int(i) for i in input().split()] print(b * (b-1) ** (a - 1))
3Python3
{ "input": [ "2 2", "1 10", "1 2", "1 1", "1 4", "1 8", "0 8", "0 13", "0 7", "0 12", "1 12", "1 3", "0 3", "0 0", "0 -1", "1 -1", "1 0", "-1 -1", "-2 -1", "-3 -1", "-3 0", "1 -2", "2 3", "0 -2", "0 4", "2 8", ...
5ATCODER
p03963 AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer_2026
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints * 1≦N≦1000 * 2≦K≦1000 * The correct answer i...
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int a = k; for (int i = 1; i < n; i++) { a *= k - 1; } System.out.println(a); } }
4JAVA
{ "input": [ "2 2", "1 10", "1 2", "1 1", "1 4", "1 8", "0 8", "0 13", "0 7", "0 12", "1 12", "1 3", "0 3", "0 0", "0 -1", "1 -1", "1 0", "-1 -1", "-2 -1", "-3 -1", "-3 0", "1 -2", "2 3", "0 -2", "0 4", "2 8", ...
5ATCODER
p00054 Sum of Nth decimal places_2027
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outputs s, and exits. Input The input consists of multiple dataset...
import sys def solv(a, b, n): x = list(str(float(a) / float(b) - a / b))[2:] x = map(int, x) if n <= len(x): return sum(x[:n]) else: return sum(x) for line in sys.stdin: a, b, n = tuple(map(int, line.split(' '))) print solv(a, b, n)
1Python2
{ "input": [ "1 2 3\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1",...
6AIZU
p00054 Sum of Nth decimal places_2028
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outputs s, and exits. Input The input consists of multiple dataset...
#include <iostream> using namespace std; int main() { int a, b, n; while (cin >> a >> b >> n) { int ans = 0; a = 10 * (a % b); while (n--) { ans += a / b; a = 10 * (a % b); } cout << ans << endl; } return 0; }
2C++
{ "input": [ "1 2 3\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1",...
6AIZU
p00054 Sum of Nth decimal places_2029
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outputs s, and exits. Input The input consists of multiple dataset...
while 1: try: a,b,c=map(int,input().split()) except:break print(sum(a*10**(i+1)//b%10 for i in range(c)))
3Python3
{ "input": [ "1 2 3\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1",...
6AIZU
p00054 Sum of Nth decimal places_2030
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outputs s, and exits. Input The input consists of multiple dataset...
import java.util.*; class Main { public static void main(String args[]) { try (Scanner sc = new Scanner(System.in)) { while (true) { int a, b, c; try { a = sc.nextInt(...
4JAVA
{ "input": [ "1 2 3\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1",...
6AIZU
p00184 Tsuruga Castle_2031
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct...
while True: n = input() if n == 0: break A = [0]*7 for _ in xrange(n): A[min(int(raw_input())/10,6)] += 1 print "\n".join(map(str,A))
1Python2
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n16\n81\n78\n65\n0", ...
6AIZU
p00184 Tsuruga Castle_2032
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct...
#include<stdio.h> int main(){ int n,ni[7],i,to; while(0<=scanf("%d",&n)){ if(n==0)break; for(i=0;i<7;i++)ni[i]=0; for(i=0;i<n;i++){ scanf("%d",&to); if(to<10){ ++ni[0]; }else if(to<20){ ++ni[1]; }else if(to<30){ ++ni[2]; }else if(to<40){ ++ni[3]; }else if(to<50){ ++n...
2C++
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n16\n81\n78\n65\n0", ...
6AIZU
p00184 Tsuruga Castle_2033
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct...
while True: n = int(input()) if n == 0: break To_lis = [0,0,0,0,0,0,0] for i in range(n): tosi = int(input()) if tosi < 10: To_lis[0] += 1 elif tosi < 20: To_lis[1] += 1 elif tosi < 30: To_lis[2] += 1 elif tosi < 40: ...
3Python3
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n16\n81\n78\n65\n0", ...
6AIZU
p00184 Tsuruga Castle_2034
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct...
import java.util.*; class Main { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); if (n == 0) { break; } int[] ages = new int[7]; int c = 0; for (int ii = 0; ii < n; ii++) { ...
4JAVA
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n16\n81\n78\n65\n0", ...
6AIZU
p00340 Rectangle_2035
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the four sticks I prepared. However, the stick must not be cut or brok...
inpt = map(int, raw_input().split()) inpt.sort() if inpt[0] == inpt[1] and inpt[2] == inpt[3]: print 'yes' else: print 'no'
1Python2
{ "input": [ "1 1 2 2", "4 4 4 10", "2 1 1 2", "1 1 3 4", "0 1 2 2", "0 0 2 2", "0 4 4 10", "2 0 1 2", "1 1 0 4", "-1 1 2 2", "1 4 4 10", "2 0 2 2", "1 1 0 6", "-1 4 4 10", "2 0 2 4", "0 1 0 6", "-1 0 2 2", "-1 1 4 10", "2 0 3 4", "0 1 1 ...
6AIZU
p00340 Rectangle_2036
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the four sticks I prepared. However, the stick must not be cut or brok...
#include <iostream> #include <algorithm> using namespace std; int main(void){ int a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3]; sort(a,a+4); if(a[0]==a[1]&&a[2]==a[3])cout<<"yes"<<endl; else cout<<"no"<<endl; return 0; }
2C++
{ "input": [ "1 1 2 2", "4 4 4 10", "2 1 1 2", "1 1 3 4", "0 1 2 2", "0 0 2 2", "0 4 4 10", "2 0 1 2", "1 1 0 4", "-1 1 2 2", "1 4 4 10", "2 0 2 2", "1 1 0 6", "-1 4 4 10", "2 0 2 4", "0 1 0 6", "-1 0 2 2", "-1 1 4 10", "2 0 3 4", "0 1 1 ...
6AIZU
p00340 Rectangle_2037
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the four sticks I prepared. However, the stick must not be cut or brok...
s = input().split() for j in range(len(s)): for k in range(j-1,-1,-1): if s[k] >= s[k+1]: s[k],s[k+1] = s[k+1],s[k] if s[1] == s[0]: if s[2] == s[3]: print("yes") else: print("no") else: print("no")
3Python3
{ "input": [ "1 1 2 2", "4 4 4 10", "2 1 1 2", "1 1 3 4", "0 1 2 2", "0 0 2 2", "0 4 4 10", "2 0 1 2", "1 1 0 4", "-1 1 2 2", "1 4 4 10", "2 0 2 2", "1 1 0 6", "-1 4 4 10", "2 0 2 4", "0 1 0 6", "-1 0 2 2", "-1 1 4 10", "2 0 3 4", "0 1 1 ...
6AIZU
p00340 Rectangle_2038
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the four sticks I prepared. However, the stick must not be cut or brok...
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] e = new int[4]; for(int i = 0; i < 4; i++) { e[i] = sc.nextInt(); } Arrays.sort(e); System.out.prin...
4JAVA
{ "input": [ "1 1 2 2", "4 4 4 10", "2 1 1 2", "1 1 3 4", "0 1 2 2", "0 0 2 2", "0 4 4 10", "2 0 1 2", "1 1 0 4", "-1 1 2 2", "1 4 4 10", "2 0 2 2", "1 1 0 6", "-1 4 4 10", "2 0 2 4", "0 1 0 6", "-1 0 2 2", "-1 1 4 10", "2 0 3 4", "0 1 1 ...
6AIZU
p00534 Silk Road_2039
problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di. JOI, a trader, decided to start from city 0, go through ...
n,m=map(int,raw_input().split()) d=[int(raw_input()) for _ in xrange(n)] c=[int(raw_input()) for _ in xrange(m)] dp=[[float('inf')]*(m+1) for _ in xrange(n+1)] for i in xrange(m+1): dp[0][i]=0 for i in xrange(n): for j in xrange(m): dp[i+1][j+1]=min(min(dp[i+1]),dp[i][j]+d[i]*c[j]) print(dp[n][m])
1Python2
{ "input": [ "3 5\n10\n25\n15\n50\n30\n15\n40\n30", "3 5\n10\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n7\n50\n30\n6\n40\n30", "1 5\n10\n38\n7\n50\n30\n6\n40\n30", "3 5\n10\n25\n15\n50\n30\n15\n12\n30", "3 5\n1\n25\n15\n50\n30\n6\n40\n30", "3 5\n10...
6AIZU
p00534 Silk Road_2040
problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di. JOI, a trader, decided to start from city 0, go through ...
#include<iostream> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define INF 1e10 using namespace std; int main(){ int n,m; cin>>n>>m; long long dp[n+1][m+1]; long long d[n+1],c[m+1]; rep(i,n+1){ rep(j,m+1){ if(i==0)dp[i][j]=0; else dp[i][j]=INF; } } loop(i,1,n+1)cin>>d[i]; lo...
2C++
{ "input": [ "3 5\n10\n25\n15\n50\n30\n15\n40\n30", "3 5\n10\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n7\n50\n30\n6\n40\n30", "1 5\n10\n38\n7\n50\n30\n6\n40\n30", "3 5\n10\n25\n15\n50\n30\n15\n12\n30", "3 5\n1\n25\n15\n50\n30\n6\n40\n30", "3 5\n10...
6AIZU
p00534 Silk Road_2041
problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di. JOI, a trader, decided to start from city 0, go through ...
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return map(int, sys.stdin.readline().split()) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i...
3Python3
{ "input": [ "3 5\n10\n25\n15\n50\n30\n15\n40\n30", "3 5\n10\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n7\n50\n30\n6\n40\n30", "1 5\n10\n38\n7\n50\n30\n6\n40\n30", "3 5\n10\n25\n15\n50\n30\n15\n12\n30", "3 5\n1\n25\n15\n50\n30\n6\n40\n30", "3 5\n10...
6AIZU
p00534 Silk Road_2042
problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di. JOI, a trader, decided to start from city 0, go through ...
import java.util.*; class Main { static Scanner scan = new Scanner(System.in); public static void main(String[] args) { int n = scan.nextInt(); int m = scan.nextInt(); int[] dist = new int[n]; int[] weather = new int[m]; int[][] dp = new int[n+1][m+1]; for (int ...
4JAVA
{ "input": [ "3 5\n10\n25\n15\n50\n30\n15\n40\n30", "3 5\n10\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n7\n50\n30\n6\n40\n30", "1 5\n10\n38\n7\n50\n30\n6\n40\n30", "3 5\n10\n25\n15\n50\n30\n15\n12\n30", "3 5\n1\n25\n15\n50\n30\n6\n40\n30", "3 5\n10...
6AIZU
p00698 Missing Numbers_2043
Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have sold in total. The type of a table that is sent to Toshizo by the stores lo...
import sys from copy import deepcopy def check(data): return reduce(lambda a, b: a+b, data).count("?") def calc(seq): if "?" not in seq or not(0 <= seq.count("?") <= 1) : return seq if seq[-1] == "?": return seq[:-1] + sum(seq[:-1]) a = seq[-1] - sum(s for s in seq[:-1] if s != "?") ...
1Python2
{ "input": [ "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 60 70 180\n70 90 110 270\n\n0", "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 100 70 180\n70 90 110 270\n\n0", ...
6AIZU
p00698 Missing Numbers_2044
Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have sold in total. The type of a table that is sent to Toshizo by the stores lo...
#include <iostream> #include <algorithm> #include <cmath> #include <vector> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; #define EPS (1e-8) const int q = -999999999; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; vec ...
2C++
{ "input": [ "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 60 70 180\n70 90 110 270\n\n0", "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 100 70 180\n70 90 110 270\n\n0", ...
6AIZU
p00698 Missing Numbers_2045
Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have sold in total. The type of a table that is sent to Toshizo by the stores lo...
import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; public class Main { public static final int P_MAX = 100; public static final int S_MAX = 10; public static void main(String[] args) { Scanner sc = new Scanner(...
4JAVA
{ "input": [ "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 60 70 180\n70 90 110 270\n\n0", "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 100 70 180\n70 90 110 270\n\n0", ...
6AIZU
p00839 Organize Your Train_2046
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytim...
#include <algorithm> #include <array> #include <cstdlib> #include <iostream> #include <queue> #include <unordered_map> #include <vector> using namespace std; template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; } typedef array<int, 2> A; typedef pair<A, A> E; typedef unsigned hash_t; hash_t rolli...
2C++
{ "input": [ "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0", "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbcdcee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E ...
6AIZU
p00839 Organize Your Train_2047
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytim...
def solve(file_input, x, y): exch1 = [] # forward - forward exch2 = [] # forward - reverse exch3 = [] # reverse - forward for i in range(y): p, P, space, q, Q = file_input.readline().rstrip() p = int(p) q = int(q) if P == 'E': if Q == 'W': ...
3Python3
{ "input": [ "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0", "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbcdcee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E ...
6AIZU
p00839 Organize Your Train_2048
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytim...
import java.util.*; public class Main { //1330 start //1430 cording end //1510 sample matched RE //1510 stop //0150 restart //0206 TLE //0228 MLE //0230 MLE modified continue to break //0233 MLE modified presentation error //0251 WA modi goal process class C{ int step; StringBuilder [] list; public ...
4JAVA
{ "input": [ "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0", "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbcdcee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E ...
6AIZU
p00971 Shortest Common Non-Subsequence_2049
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCESSOR". A common subsequence of two sequences is a subsequence of both seque...
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; (i) < (n); ++(i)) #define REP3(i,m,n) for (int i = (m); (i) < (n); ++(i)) #define REP_R(i,n) for (int i = (int)(n) - 1; (i) >= 0; --(i)) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; template <class T> inline void chmin(T & a, T cons...
2C++
{ "input": [ "0101\n1100001", "0101\n1101001", "0101\n1100000", "0101\n1101000", "0101\n0001000", "0101\n0011001", "0101\n0110001", "0101\n1111001", "0101\n1001001", "0101\n0001101", "0101\n0101001", "0101\n0100101", "0101\n1000110", "0101\n1001010", "0101\n...
6AIZU
p00971 Shortest Common Non-Subsequence_2050
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCESSOR". A common subsequence of two sequences is a subsequence of both seque...
def main(): p=input() q=input() lp=len(p) lq=len(q) memop=[[0,0] for _ in [0]*(lp+2)] memoq=[[0,0] for _ in [0]*(lq+2)] memop[lp+1]=[lp+1,lp+1] memoq[lq+1]=[lq+1,lq+1] memop[lp]=[lp+1,lp+1] memoq[lq]=[lq+1,lq+1] for i in range(lp-1,-1,-1): if p[i]=="0": ...
3Python3
{ "input": [ "0101\n1100001", "0101\n1101001", "0101\n1100000", "0101\n1101000", "0101\n0001000", "0101\n0011001", "0101\n0110001", "0101\n1111001", "0101\n1001001", "0101\n0001101", "0101\n0101001", "0101\n0100101", "0101\n1000110", "0101\n1001010", "0101\n...
6AIZU
p00971 Shortest Common Non-Subsequence_2051
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCESSOR". A common subsequence of two sequences is a subsequence of both seque...
import java.io.PrintWriter; import java.util.*; public class Main { private static int n, m; private static char[] s, t; private static int[][] sp, tp; private static short[][] dp; public static void main(String[] args) { try (Scanner in = new Scanner(System.in); PrintWriter out = new Prin...
4JAVA
{ "input": [ "0101\n1100001", "0101\n1101001", "0101\n1100000", "0101\n1101000", "0101\n0001000", "0101\n0011001", "0101\n0110001", "0101\n1111001", "0101\n1001001", "0101\n0001101", "0101\n0101001", "0101\n0100101", "0101\n1000110", "0101\n1001010", "0101\n...
6AIZU
p01103 A Garden with Ponds_2052
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple ...
# coding: utf-8 def func(lx, rx, ly, ry, e): ret = 0 soto_min = 0xdeadbeef for i in range(lx, rx+1): for j in range(ly, ry+1): if i == lx or i == rx or j == ly or j == ry: soto_min = min(soto_min, e[j][i]) for i in range(lx, rx+1): for j in range(ly, ry+1):...
1Python2
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3...
6AIZU
p01103 A Garden with Ponds_2053
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple ...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> mp; ll inf = 1e9; int main(){ while(1){ ll h,w; cin>>h>>w; if( h==0 && w==0 ) break; vector<vector<ll> > e(h+2,vector<ll>(w+2,0) ); for(ll i=1;i<=h;i++)for(ll j=1;j<=w;j++) cin>>e[i][j]; ll res = 0; for(ll l=1;l<=h;l++...
2C++
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3...
6AIZU
p01103 A Garden with Ponds_2054
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple ...
while True: d, w = map(int, input().split()) if d == 0:break mp = [list(map(int, input().split())) for _ in range(d)] def solve(): ans = 0 for left in range(w - 1): for right in range(w - 1, left + 1, -1): for top in range(d - 1): for under in range(d - 1, top + 1, -1): ...
3Python3
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3...
6AIZU
p01103 A Garden with Ponds_2055
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple ...
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner s=new Scanner(System.in); while(true){ int d=s.nextInt(); int w=s.nextInt(); if(d==0&&w==0) break; int depth[][]=new int[d][w]; for(int i=0;i<d;i++...
4JAVA
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3...
6AIZU
p01240 Oil Company_2056
Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil. They are now planning to construct mining plants on several grid blocks according this map, but they decided no...
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)(n);...
2C++
{ "input": [ "2\n2 2\n2 3\n3 5\n3 2\n4 1 1\n2 1 4", "2\n2 2\n2 3\n3 5\n3 2\n4 1 1\n2 1 0", "2\n2 0\n2 3\n3 5\n3 2\n4 1 1\n2 1 0", "2\n2 0\n2 3\n3 5\n3 3\n4 1 1\n2 1 0", "2\n1 1\n2 3\n3 5\n3 3\n4 1 1\n2 2 0", "2\n1 1\n2 2\n3 5\n3 3\n4 1 1\n2 2 0", "2\n1 1\n2 2\n3 5\n3 3\n6 1 1\n2 2 0", ...
6AIZU
p01402 Anipero_2057
Problem E: Anipero The long and short summer, which had been hot, was about to end. One day in late August, a person who likes 2D and his senior slip participated in an event called Anipero Summer Live, commonly known as Anipero. Anipero is the largest anime song live event in Japan where various anime song artists ga...
#include<stdio.h> #include<algorithm> using namespace std; char in[100]; int dp[110][1010]; int val[1010]; int sp[110]; int sq[110]; int np[110]; int nq[110]; int main(){ int a,b,c,d; while(scanf("%d%d%d%d",&a,&b,&c,&d),a){ for(int i=0;i<b;i++){ scanf("%s%d%d",in,sp+i,sq+i); } for(int i=0;i<c;i++)scanf("%s%d...
2C++
{ "input": [ "100 2 2 2\nA 5 6\nB 7 8\nC 1 2\nD 3 4\n27 2 3 3\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n27 2 3 2\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n44 3 6 5\nYamatoNoHito 9 10\nZettoNoHito 9 10\nTMR 10 10\nSkillNoGroup 8 10\nNanaSama 6 9\nFRPSD 6 8\nMagi3rdDeshi 5 7\nMagi13thDeshi 2 2\nMagicalItoh 4 6\n0 0 0 0", ...
6AIZU
p01402 Anipero_2058
Problem E: Anipero The long and short summer, which had been hot, was about to end. One day in late August, a person who likes 2D and his senior slip participated in an event called Anipero Summer Live, commonly known as Anipero. Anipero is the largest anime song live event in Japan where various anime song artists ga...
import java.util.Scanner; //Anipero public class Main{ void run(){ Scanner sc = new Scanner(System.in); for(;;){ int L = sc.nextInt(), n = sc.nextInt(), m = sc.nextInt(), X = sc.nextInt(); if((L|n|m|X)==0)break; int[] e1 = new int[n], s1 = new int[n]; for(int i=0;i<n;i++){ sc.next(); e1[i] = sc.n...
4JAVA
{ "input": [ "100 2 2 2\nA 5 6\nB 7 8\nC 1 2\nD 3 4\n27 2 3 3\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n27 2 3 2\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n44 3 6 5\nYamatoNoHito 9 10\nZettoNoHito 9 10\nTMR 10 10\nSkillNoGroup 8 10\nNanaSama 6 9\nFRPSD 6 8\nMagi3rdDeshi 5 7\nMagi13thDeshi 2 2\nMagicalItoh 4 6\n0 0 0 0", ...
6AIZU
p01556 ConvexCut_2059
A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are eq...
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) N = input() lst = [] for i in range(N): X, Y = map(int, raw_input().split()) lst.append((X, Y)) if N % 2 != 0: print "NA" exit() ansx = lst[0][0] + lst[N / 2][0] ansy = lst[0][1] + ...
1Python2
{ "input": [ "4\n100 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n0 0", "4\n000 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 0", "4\n000 101\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 1", "4\n000 101\n0 000\n0 0\n100 0", "3\n100 100\n0 000\n1 1", "4\n000 101\n0 000\n0 0\n110 0", ...
6AIZU
p01556 ConvexCut_2060
A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are eq...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PI; const double EPS=1e-8; #define rep(i,n) for(int i=0;i<(int)(n);++i) #define F first #define S second #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define SZ(a) (int)((a).size()) #define ALL(a) (a).begin(),(a).end...
2C++
{ "input": [ "4\n100 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n0 0", "4\n000 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 0", "4\n000 101\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 1", "4\n000 101\n0 000\n0 0\n100 0", "3\n100 100\n0 000\n1 1", "4\n000 101\n0 000\n0 0\n110 0", ...
6AIZU
p01556 ConvexCut_2061
A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are eq...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
3Python3
{ "input": [ "4\n100 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n0 0", "4\n000 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 0", "4\n000 101\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 1", "4\n000 101\n0 000\n0 0\n100 0", "3\n100 100\n0 000\n1 1", "4\n000 101\n0 000\n0 0\n110 0", ...
6AIZU
p01556 ConvexCut_2062
A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are eq...
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int N = sc.nextInt(); if (N % 2 != 0) { System.out.println("NA"); return; } int[] X = new int[N]; int[] Y = new int[N]; int sx = 0; int sy = 0; for (int i = 0; i <...
4JAVA
{ "input": [ "4\n100 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n0 0", "4\n000 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 0", "4\n000 101\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 1", "4\n000 101\n0 000\n0 0\n100 0", "3\n100 100\n0 000\n1 1", "4\n000 101\n0 000\n0 0\n110 0", ...
6AIZU
p01711 Idempotent Filter_2063
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) "Filtering" is an operation to determine the color of a...
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <...
2C++
{ "input": [ "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101...
6AIZU
p01711 Idempotent Filter_2064
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) "Filtering" is an operation to determine the color of a...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
3Python3
{ "input": [ "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101...
6AIZU
p01711 Idempotent Filter_2065
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) "Filtering" is an operation to determine the color of a...
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int[] filter = new int[1 << 7]; public static void main(String[] args) { while (sc.hasNext()) { char[] input = sc.next().toCharArray(); if (input.length != filter.length) break; for (int j = 0; j < filter.le...
4JAVA
{ "input": [ "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101...
6AIZU
p01856 Typhoon_2066
Problem statement There is a town with a size of H in the north-south direction and W in the east-west direction. In the town, square plots with a side length of 1 are maintained without gaps, and one house is built in each plot. A typhoon broke out over a section of the town, causing damage and then changing to an e...
#include<iostream> #include<vector> #include<algorithm> #include<utility> using namespace std; int D[523][523]; int g[523][523]; int cnt,fx,fy; void find(int y,int x){ if(D[y][x]){ fy=y+1; fx=x+1; cnt++; int p=D[y][x]; g[fy][fx]=p; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ D[y+i][x...
2C++
{ "input": [ "7 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "14 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "10 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "18 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 ...
6AIZU
p01991 Namo.. Cut_2067
C: Namo .. Cut problem -Defeat the mysterious giant jellyfish, codenamed "Nari"- "Nari" has a very strong vitality, so if you don't keep cutting quickly, it will be revived in a blink of an eye. We are making trial and error every day to find out how to cut "Nari" efficiently. In the process, you needed the help of ...
#include<iostream> #include<vector> #include<algorithm> using namespace std; using ll = long long; #define FOR(i,k,n) for(ll (i)=(k);(i)<(n);(i)++) #define REP(i,n) FOR((i),0,(n)) ll N, Q; vector<vector<ll>> edges; vector<pair<ll, ll>> query; void input() { ll a, b; cin >> N; edges.resize(N); REP(i, N) { cin...
2C++
{ "input": [ "3\n1 2\n1 3\n2 3\n1\n1 3", "3\n1 2\n1 3\n2 3\n1\n1 2", "3\n1 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n2 1\n2\n2 3", "3\n1 2\n1 3\n2 3\n2\n2 3", "3\n2 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n3 3\n1\n1 4", "3\n2 2\n1 3\n2 3\n1\n1 4", "3\n1 2\n1 1\n2 3\n1\n1 3", "3\n2 2\n1 3\...
6AIZU
p01991 Namo.. Cut_2068
C: Namo .. Cut problem -Defeat the mysterious giant jellyfish, codenamed "Nari"- "Nari" has a very strong vitality, so if you don't keep cutting quickly, it will be revived in a blink of an eye. We are making trial and error every day to find out how to cut "Nari" efficiently. In the process, you needed the help of ...
# サイクル検出 import sys sys.setrecursionlimit(10**7) def dfs(G, v, p): global pos seen[v] = True hist.append(v) for nv in G[v]: # 逆流を禁止する if nv == p: continue # 完全終了した頂点はスルー if finished[nv]: continue # サイクルを検出 if seen[nv] and not fi...
3Python3
{ "input": [ "3\n1 2\n1 3\n2 3\n1\n1 3", "3\n1 2\n1 3\n2 3\n1\n1 2", "3\n1 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n2 1\n2\n2 3", "3\n1 2\n1 3\n2 3\n2\n2 3", "3\n2 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n3 3\n1\n1 4", "3\n2 2\n1 3\n2 3\n1\n1 4", "3\n1 2\n1 1\n2 3\n1\n1 3", "3\n2 2\n1 3\...
6AIZU
p01991 Namo.. Cut_2069
C: Namo .. Cut problem -Defeat the mysterious giant jellyfish, codenamed "Nari"- "Nari" has a very strong vitality, so if you don't keep cutting quickly, it will be revived in a blink of an eye. We are making trial and error every day to find out how to cut "Nari" efficiently. In the process, you needed the help of ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Queue; import java.u...
4JAVA
{ "input": [ "3\n1 2\n1 3\n2 3\n1\n1 3", "3\n1 2\n1 3\n2 3\n1\n1 2", "3\n1 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n2 1\n2\n2 3", "3\n1 2\n1 3\n2 3\n2\n2 3", "3\n2 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n3 3\n1\n1 4", "3\n2 2\n1 3\n2 3\n1\n1 4", "3\n1 2\n1 1\n2 3\n1\n1 3", "3\n2 2\n1 3\...
6AIZU
p02137 Special Chat_2070
Problem The popular video posting site "ZouTube" is now in the midst of an unprecedented "virtual ZouTuber" boom. Among them, the one that has been attracting particular attention recently is the junior virtual ZouTuber "Aizumarim (commonly known as Azurim)". As a big fan of Azlim, you're going to send her a "special...
N = input() print N / 500 * 500
1Python2
{ "input": [ "1333", "5700", "100000", "2178", "9648", "000000", "1978", "3066", "4226", "2548", "5031", "1305", "110000", "5613", "638", "3852", "10955", "7666", "6581", "12541", "6338", "12473", "9117", "4887", "1515...
6AIZU
p02137 Special Chat_2071
Problem The popular video posting site "ZouTube" is now in the midst of an unprecedented "virtual ZouTuber" boom. Among them, the one that has been attracting particular attention recently is the junior virtual ZouTuber "Aizumarim (commonly known as Azurim)". As a big fan of Azlim, you're going to send her a "special...
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #in...
2C++
{ "input": [ "1333", "5700", "100000", "2178", "9648", "000000", "1978", "3066", "4226", "2548", "5031", "1305", "110000", "5613", "638", "3852", "10955", "7666", "6581", "12541", "6338", "12473", "9117", "4887", "1515...
6AIZU
p02137 Special Chat_2072
Problem The popular video posting site "ZouTube" is now in the midst of an unprecedented "virtual ZouTuber" boom. Among them, the one that has been attracting particular attention recently is the junior virtual ZouTuber "Aizumarim (commonly known as Azurim)". As a big fan of Azlim, you're going to send her a "special...
print(int(input())//500*500)
3Python3
{ "input": [ "1333", "5700", "100000", "2178", "9648", "000000", "1978", "3066", "4226", "2548", "5031", "1305", "110000", "5613", "638", "3852", "10955", "7666", "6581", "12541", "6338", "12473", "9117", "4887", "1515...
6AIZU
p02137 Special Chat_2073
Problem The popular video posting site "ZouTube" is now in the midst of an unprecedented "virtual ZouTuber" boom. Among them, the one that has been attracting particular attention recently is the junior virtual ZouTuber "Aizumarim (commonly known as Azurim)". As a big fan of Azlim, you're going to send her a "special...
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int N = sc.nextInt(); System.out.println(N - (N % 500)); } } }
4JAVA
{ "input": [ "1333", "5700", "100000", "2178", "9648", "000000", "1978", "3066", "4226", "2548", "5031", "1305", "110000", "5613", "638", "3852", "10955", "7666", "6581", "12541", "6338", "12473", "9117", "4887", "1515...
6AIZU
p02278 Minimum Cost Sort_2074
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to...
n = int(raw_input()) W = map(int, raw_input().split()) s = min(W) T = [0] * (max(W)+1) def solve(): ans = 0 B = W[:] V = [False] * n B.sort() for i in xrange(n): T[B[i]] = i for i in xrange(n): if V[i]: continue cur = i S = 0 m = max(W)+1 ...
1Python2
{ "input": [ "4\n4 3 2 1", "5\n1 5 3 4 2", "4\n8 3 2 1", "5\n0 5 3 4 2", "5\n0 5 3 1 2", "5\n1 8 3 4 2", "5\n0 9 3 1 2", "5\n1 8 3 4 0", "5\n0 15 3 1 2", "5\n1 5 3 8 2", "5\n0 5 6 4 2", "5\n0 5 3 1 4", "5\n0 19 3 1 2", "4\n3 5 2 1", "5\n0 5 6 4 3", "5\n0...
6AIZU
p02278 Minimum Cost Sort_2075
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to...
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<list> #include<string> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; int main(void) { int n, W, MIN = 100001, sum = 0, p = 0, pp, cost = 0, k = 0, min = 100001; cin >> n; vect...
2C++
{ "input": [ "4\n4 3 2 1", "5\n1 5 3 4 2", "4\n8 3 2 1", "5\n0 5 3 4 2", "5\n0 5 3 1 2", "5\n1 8 3 4 2", "5\n0 9 3 1 2", "5\n1 8 3 4 0", "5\n0 15 3 1 2", "5\n1 5 3 8 2", "5\n0 5 6 4 2", "5\n0 5 3 1 4", "5\n0 19 3 1 2", "4\n3 5 2 1", "5\n0 5 6 4 3", "5\n0...
6AIZU
p02278 Minimum Cost Sort_2076
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to...
n = int(input()) A = [int(i) for i in input().split()] B = A.copy() B.sort() ans = 0 for i in B: ixB = B.index(i) counter = 0 while(True): ixA = A.index(i) if ixA == ixB: break else: counter += 1 num = B[ixA] ixN = A.index(num) ...
3Python3
{ "input": [ "4\n4 3 2 1", "5\n1 5 3 4 2", "4\n8 3 2 1", "5\n0 5 3 4 2", "5\n0 5 3 1 2", "5\n1 8 3 4 2", "5\n0 9 3 1 2", "5\n1 8 3 4 0", "5\n0 15 3 1 2", "5\n1 5 3 8 2", "5\n0 5 6 4 2", "5\n0 5 3 1 4", "5\n0 19 3 1 2", "4\n3 5 2 1", "5\n0 5 6 4 3", "5\n0...
6AIZU
p02278 Minimum Cost Sort_2077
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to...
import java.util.Arrays; import java.util.Scanner; /** * Created by zhangrunfeng on 2/18/20 */ public class Main { private int N; private int[] arr; private int[] T; private boolean[] v; private int minVal; public Main(Scanner sc) { N = sc.nextInt(); arr = new int[N]; ...
4JAVA
{ "input": [ "4\n4 3 2 1", "5\n1 5 3 4 2", "4\n8 3 2 1", "5\n0 5 3 4 2", "5\n0 5 3 1 2", "5\n1 8 3 4 2", "5\n0 9 3 1 2", "5\n1 8 3 4 0", "5\n0 15 3 1 2", "5\n1 5 3 8 2", "5\n0 5 6 4 2", "5\n0 5 3 1 4", "5\n0 19 3 1 2", "4\n3 5 2 1", "5\n0 5 6 4 3", "5\n0...
6AIZU
p02425 Bit Flag_2078
A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bits with 6...
#include <iostream> #include <bitset> int main() { std::bitset<64> bs(0); int q; std::cin >> q; for (int i=0; i<q; i++) { int op, k; std::cin >> op; switch (op) { case 0: std::cin >> k; std::cout << bs.test(k) << std::endl; break; case 1: std::cin >> k; bs.set(k); break; case 2: ...
2C++
{ "input": [ "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n1 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n2 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2...
6AIZU
p02425 Bit Flag_2079
A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bits with 6...
q = int(input()) bit_flag = 0 BIT_MASK = (1 << 64) - 1 for _ in range(q): command, *list_num = input().split() if command == "0": # test(i) i = int(list_num[0]) if bit_flag & (2 ** i): print(1) else: print(0) elif command == "1": # set(i)...
3Python3
{ "input": [ "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n1 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n2 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2...
6AIZU
p02425 Bit Flag_2080
A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bits with 6...
import java.io.*; import java.util.*; import java.math.*; class Main{ static final int nbits = 64; public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); String[] str = br.readLine().spli...
4JAVA
{ "input": [ "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n1 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n2 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2...
6AIZU
appuzzle_2081
Arithmetic and geometric Progressions are 2 of the well known progressions in maths. Arithmetic progression (AP) is a set in which the difference between 2 numbers in constant. for eg, 1,3,5,7,9....In this series the difference between 2 numbers is 2.The task here is very simple indeed. You will be given the 3rd term ,...
for _ in range(input()): aa,nn,s=map(int,raw_input().split()) sum=aa+nn n=(2*s)/sum d=(nn-aa)/(n-5) a=aa-2*d print n for i in range(1,n+1): print a+(i-1)*d, print
1Python2
{ "input": [ "1\n3 8 55", "1\n3 14 55", "1\n3 14 83", "1\n3 14 99", "1\n3 4 95", "1\n6 4 95", "1\n6 4 142", "1\n6 4 261", "1\n1 4 261", "1\n1 4 240", "1\n1 4 228", "1\n1 4 245", "1\n1 4 448", "1\n1 6 448", "1\n1 6 482", "1\n1 2 482", "1\n2 2 482", ...
1CODECHEF
cielrcpt_2082
Tomya is a girl. She loves Chef Ciel very much. Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p. The current menus of Ciel's restaurant are shown the following table. Name of Menuprice eel flavored water1 deep-fried eel bones2 clear soup made w...
menu = [1,2,4,8,16,32,64,128,256,512,1024,2048] menu.reverse() def find_menus(price, count): if price==0: return count for i in menu: if price/i>0: return find_menus(price%i, count+price/i) for i in range(input()): print find_menus(input(), 0)
1Python2
{ "input": [ "4\n10\n256\n255\n4096", "4\n10\n376\n255\n4096", "4\n10\n376\n255\n3088", "4\n11\n376\n255\n3088", "4\n11\n376\n255\n4598", "4\n11\n73\n255\n4598", "4\n11\n73\n255\n2919", "4\n8\n73\n255\n2919", "4\n8\n73\n94\n2919", "4\n14\n73\n94\n2919", "4\n14\n92\n94\n2919...
1CODECHEF
exebit01_2083
Pratyush, a six year old kid has just learnt how to write 1 through 1000 in decimal number system(DNS). Being a very curious kid, he made some modifications in DNS and removed the digits 0 through 3 and 7 through 9. So the only digits remaining to be used are 4, 5 and 6. He started enumerating numbers with these digits...
t=int(input()) while(t): t=t-1 n=int(input()) k=1 ans=0 while(n>0): if(n%3==0): ans=6*k+ans n=n/3-1 elif(n%3==1): ans=4*k+ans n=(n-1)/3 elif(n%3==2): ans=5*k+ans n=(n-2)/3 k=k*10 print ans
1Python2
{ "input": [ "5\n3\n13\n45\n64\n1000000000" ], "output": [ "6\n444\n4456\n4664\n5446456455646565564" ] }
1CODECHEF
lastride_2084
Problem description. Toretto has no friends. He has got family, and now they need him. His bitter enemy, Ian Shaw, has captured Toretto's beloved Letty and evil cooks in his head. All Toretto has is the algorithmic message Shaw left before leaving- Letty(n): L = an empty list while n > 0: find the larg...
import sys f = sys.stdin mod = 1000000007 DP = [0]*(2) DP[0] = [0]*(111) DP[1] = [0]*(111) bits = [0]*(111) X = [0]*(2) Y = [0]*(2) X[0] = [0]*(111) X[1] = [0]*(111) Y[0] = [0]*(111) Y[1] = [0]*(111) def process(): DP[0][100] = 1 DP[1][100] = 1 X[0][100] = 1 Y[0][100] = 0 Y[1][100] = 1 X[1][100...
1Python2
{ "input": [ "2\n1 2\n3 10" ], "output": [ "3\n25" ] }
1CODECHEF
pd32_2085
Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n ≥ 3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b]. Input The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is...
import bisect def find_lt(a,x): #find rightmost value less than or equal to x i=bisect.bisect_right(a,x) if i: return i-1 else: return -1 def find_ge(a,x): #find leftmost item greator than or equal to x i=bisect.bisect_left(a,x) if i!=len(a): return i else: ...
1Python2
{ "input": [ "10 100\n1234567890 9876543210\n0 0" ], "output": [ "5\n4" ] }
1CODECHEF
stfm_2086
For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p1) + F(p2) + ... + F(pn). As answer could be large, help him, calculate value modulo m. Input First line contains two integers n and m. Next line c...
arr=[] def fact(x,m): f=1 i=1; while i <=x+1: f=(f*i)%m arr.append(f) i+=1 def f(x): if x>=m: return (x*x*(x+1)/2-1)%m else: return arr[x]+x*x*(x+1)/2-1 n,m=map(int,raw_input().split()) a=map(int,raw_input().split()) x=max(a) if x<=1000000: fact(x,m) el...
1Python2
{ "input": [ "5 7\n1 2 3 4 5", "5 7\n1 2 3 4 4", "5 13\n1 2 3 4 4", "5 13\n1 2 0 4 4", "5 7\n1 2 3 4 3", "5 13\n1 4 3 4 4", "5 13\n1 3 0 4 4", "5 13\n1 3 0 4 6", "5 7\n1 0 0 5 4", "5 6\n0 2 4 4 6", "1 13\n1 17 0 4 6", "5 17\n1 6 0 4 3", "1 20\n1 17 2 0 6", "1 10...
1CODECHEF
1008_D. Pave the Parallelepiped_2087
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same d...
fac=[0 for i in range(100001)] for i in range(1,100001): for j in range(i,100001,i): fac[j]+=1 def gcd(a,b): if a<b: a,b=b,a while b>0: a,b=b,a%b return a n=input() for i in range(n): A,B,C = map(int,raw_input().split()) la=fac[A] lb=fac[B] lc=...
1Python2
{ "input": [ "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "1\n100000 100000 100000\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 5\n1 1 8\n2 8 1\n10 ...
2CODEFORCES
1008_D. Pave the Parallelepiped_2088
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same d...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; long long fac[MAXN], ft[8]; long long C[1000][1000]; int num[8]; void Init() { for (int i = 1; i < MAXN; i++) for (int j = i; j < MAXN; j += i) fac[j]++; memset(C, 0, sizeof(C)); for (int i = 0; i < 1000; i++) { C[i][0] = 1; for ...
2C++
{ "input": [ "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "1\n100000 100000 100000\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 5\n1 1 8\n2 8 1\n10 ...
2CODEFORCES
1008_D. Pave the Parallelepiped_2089
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same d...
from sys import stdin from math import gcd def main(): input() l = stdin.read().splitlines() d = [3., 1., 2., 2., 2., 1.] * 16667 for i in range(4, 100001): for j in range(i, 100001, i): d[j] += 1. for i, s in enumerate(l): a, b, c = map(int, s.split()) k = gcd(...
3Python3
{ "input": [ "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "1\n100000 100000 100000\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 5\n1 1 8\n2 8 1\n10 ...
2CODEFORCES
1008_D. Pave the Parallelepiped_2090
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same d...
import java.util.Scanner; public class Main { public static int gcd(int x, int y) { if(x == y) { return x; } if(x == 0) { return y; } if(y == 0) { return x; } if(x > y) { return gcd(x % y, y); } else { return gcd(y % x, x); } } public static long c(long n, long r) { if(r ==...
4JAVA
{ "input": [ "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "1\n100000 100000 100000\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 5\n1 1 8\n2 8 1\n10 ...
2CODEFORCES
1031_B. Curiosity Has No Limits_2091
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3). Masha became interested if or not there is an integer sequence of length n, which e...
from sys import stdin rints = lambda: [int(x) for x in stdin.readline().split()] n, a, b = int(input()), rints(), rints() mem = [[-1 for _ in range(4)] for _ in range(n)] for i in range(n - 1): for j in range(4): if mem[i][j] != -1 or not i: for k in range(4): and1, or1 = k & j...
1Python2
{ "input": [ "4\n3 3 2\n1 2 0\n", "3\n1 3\n3 2\n", "2\n2\n0\n", "50\n3 1 2 2 3 1 1 1 3 3 1 0 2 0 1 1 0 0 1 2 2 0 0 0 2 3 0 3 1 2 0 3 0 0 1 0 3 3 1 3 1 1 2 3 1 3 2 1 3\n2 1 1 1 1 0 2 2 0 1 2 3 0 1 0 1 1 1 0 0 3 1 3 3 1 0 0 1 1 2 0 2 1 1 2 0 0 0 0 2 3 3 0 1 1 1 0 2 0\n", "2\n2\n3\n", "2\n1\n0\n"...
2CODEFORCES
1031_B. Curiosity Has No Limits_2092
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3). Masha became interested if or not there is an integer sequence of length n, which e...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n - 1), b(n - 1); for (int i = 0; i < n - 1; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int t = 0; t < 4; t++) { vector<int> ans; ans.push_...
2C++
{ "input": [ "4\n3 3 2\n1 2 0\n", "3\n1 3\n3 2\n", "2\n2\n0\n", "50\n3 1 2 2 3 1 1 1 3 3 1 0 2 0 1 1 0 0 1 2 2 0 0 0 2 3 0 3 1 2 0 3 0 0 1 0 3 3 1 3 1 1 2 3 1 3 2 1 3\n2 1 1 1 1 0 2 2 0 1 2 3 0 1 0 1 1 1 0 0 3 1 3 3 1 0 0 1 1 2 0 2 1 1 2 0 0 0 0 2 3 3 0 1 1 1 0 2 0\n", "2\n2\n3\n", "2\n1\n0\n"...
2CODEFORCES
1031_B. Curiosity Has No Limits_2093
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3). Masha became interested if or not there is an integer sequence of length n, which e...
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict import threading BUFSIZE = 8192 clas...
3Python3
{ "input": [ "4\n3 3 2\n1 2 0\n", "3\n1 3\n3 2\n", "2\n2\n0\n", "50\n3 1 2 2 3 1 1 1 3 3 1 0 2 0 1 1 0 0 1 2 2 0 0 0 2 3 0 3 1 2 0 3 0 0 1 0 3 3 1 3 1 1 2 3 1 3 2 1 3\n2 1 1 1 1 0 2 2 0 1 2 3 0 1 0 1 1 1 0 0 3 1 3 3 1 0 0 1 1 2 0 2 1 1 2 0 0 0 0 2 3 3 0 1 1 1 0 2 0\n", "2\n2\n3\n", "2\n1\n0\n"...
2CODEFORCES
1031_B. Curiosity Has No Limits_2094
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3). Masha became interested if or not there is an integer sequence of length n, which e...
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n - 1; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n - 1; i++) { b[i] = in.nextI...
4JAVA
{ "input": [ "4\n3 3 2\n1 2 0\n", "3\n1 3\n3 2\n", "2\n2\n0\n", "50\n3 1 2 2 3 1 1 1 3 3 1 0 2 0 1 1 0 0 1 2 2 0 0 0 2 3 0 3 1 2 0 3 0 0 1 0 3 3 1 3 1 1 2 3 1 3 2 1 3\n2 1 1 1 1 0 2 2 0 1 2 3 0 1 0 1 1 1 0 0 3 1 3 3 1 0 0 1 1 2 0 2 1 1 2 0 0 0 0 2 3 3 0 1 1 1 0 2 0\n", "2\n2\n3\n", "2\n1\n0\n"...
2CODEFORCES
1054_B. Appending Mex_2095
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0...
""" What I cannot create, I do not understand. https://github.com/Cheran-Senthil/PyRival Copyright (c) 2018 Cheran Senthilkumar """ # IMPORTS---------------------------------------------------------------------# from __future__ import division, print_function import itertools import sys from atexit import register fr...
1Python2
{ "input": [ "3\n1 0 1\n", "4\n0 1 2 1\n", "4\n0 1 2 239\n", "2\n0 1\n", "3\n0 1 1000000000\n", "3\n0 2 4\n", "1\n1\n", "2\n0 0\n", "2\n0 1000000000\n", "2\n1 1\n", "5\n0 0 0 0 0\n", "2\n1 2\n", "1\n1000000000\n", "5\n0 0 2 2 3\n", "2\n0 2\n", "4\n0 0 2 ...
2CODEFORCES
1054_B. Appending Mex_2096
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
2C++
{ "input": [ "3\n1 0 1\n", "4\n0 1 2 1\n", "4\n0 1 2 239\n", "2\n0 1\n", "3\n0 1 1000000000\n", "3\n0 2 4\n", "1\n1\n", "2\n0 0\n", "2\n0 1000000000\n", "2\n1 1\n", "5\n0 0 0 0 0\n", "2\n1 2\n", "1\n1000000000\n", "5\n0 0 2 2 3\n", "2\n0 2\n", "4\n0 0 2 ...
2CODEFORCES
1054_B. Appending Mex_2097
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0...
n = int(input()) data = input().split() max = 0 for i in range(n): back = max if max<int(data[i]): max=int(data[i]) if i==0 and data[i]!="0": print(1) exit() elif int(data[i])>back+1: print(i+1) exit() if int(data[i])<=back+1: print(-1)
3Python3
{ "input": [ "3\n1 0 1\n", "4\n0 1 2 1\n", "4\n0 1 2 239\n", "2\n0 1\n", "3\n0 1 1000000000\n", "3\n0 2 4\n", "1\n1\n", "2\n0 0\n", "2\n0 1000000000\n", "2\n1 1\n", "5\n0 0 0 0 0\n", "2\n1 2\n", "1\n1000000000\n", "5\n0 0 2 2 3\n", "2\n0 2\n", "4\n0 0 2 ...
2CODEFORCES
1054_B. Appending Mex_2098
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0...
import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Solution { public static int serch(int[] a,int n){ int k = 0; for(int i=0;i<n;i++){ if(a[i]>k) return i+1; if(a[i]==k) k++; } return -1; }...
4JAVA
{ "input": [ "3\n1 0 1\n", "4\n0 1 2 1\n", "4\n0 1 2 239\n", "2\n0 1\n", "3\n0 1 1000000000\n", "3\n0 2 4\n", "1\n1\n", "2\n0 0\n", "2\n0 1000000000\n", "2\n1 1\n", "5\n0 0 0 0 0\n", "2\n1 2\n", "1\n1000000000\n", "5\n0 0 2 2 3\n", "2\n0 2\n", "4\n0 0 2 ...
2CODEFORCES
1076_B. Divisor Subtraction_2099
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
import math n = int(raw_input()) if n == 0: print 0 exit() if n % 2 == 0: print n//2 exit() for i in xrange(3, int(math.sqrt(n) + 1), 2): if n % i == 0: print (n-i)//2 + 1 exit() print 1
1Python2
{ "input": [ "4\n", "5\n", "9999999999\n", "10000000000\n", "9999999967\n", "2\n", "6969696\n", "473\n", "9998200081\n", "3000000021\n", "186627465\n", "10000000010\n", "4868692902\n", "6\n", "7434214\n", "261\n", "2351148436\n", "4156825468\n", ...
2CODEFORCES