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
p02943 AtCoder Grand Contest 037 - Reversing and Concatenating_1400
Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, an...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); try { final int N = sc.nextInt(); int K = sc.nextInt(); StringBuilder S = new StringBuilder(sc.next()); boolean firstTime = true; int step = 1; ...
4JAVA
{ "input": [ "5 1\nbacba", "10 2\nbbaabbbaab", "5 2\nbacba", "10 2\nbbbabbbaaa", "10 3\nbbaabbbaab", "5 2\nbacaa", "10 2\nbaabbbaabb", "10 2\nbaabbaaabb", "10 2\nbbaaabbbab", "5 1\nbabba", "10 2\nbabbbbaabb", "10 1\nbaabbaaabb", "5 1\nbabbb", "10 2\nbbaabbbbab",...
5ATCODER
p03080 ExaWizards 2019 - Red or Blue_1401
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat. Constraints * 1 \l...
n = input() s = raw_input() r = s.count("R") b = s.count("B") if r > b: print "Yes" else: print "No"
1Python2
{ "input": [ "4\nRRBR", "4\nBRBR", "4\nRBRR", "4\nBBRR", "4\nRRCR", "4\nRRAR", "4\nRARR", "4\nBQBR", "4\nRCRR", "4\nBPBR", "4\nRRRC", "4\nAQBR", "4\nRRRD", "4\nAQBS", "4\nDRRR", "4\nARBS", "4\nERRR", "4\nBQBS", "4\nBPBS", "4\nPBBS", "...
5ATCODER
p03080 ExaWizards 2019 - Red or Blue_1402
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat. Constraints * 1 \l...
#include <iostream> using namespace std; int main() { int n,cR=0,cB=0; cin>>n; while(n--) { char s; cin>>s; if(s=='R') cR++; else cB++; } if(cR>cB) cout<<"Yes"; else cout<<"No"; return 0; }
2C++
{ "input": [ "4\nRRBR", "4\nBRBR", "4\nRBRR", "4\nBBRR", "4\nRRCR", "4\nRRAR", "4\nRARR", "4\nBQBR", "4\nRCRR", "4\nBPBR", "4\nRRRC", "4\nAQBR", "4\nRRRD", "4\nAQBS", "4\nDRRR", "4\nARBS", "4\nERRR", "4\nBQBS", "4\nBPBS", "4\nPBBS", "...
5ATCODER
p03080 ExaWizards 2019 - Red or Blue_1403
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat. Constraints * 1 \l...
n = input() s = input() if s.count('R') > s.count('B') : print('Yes') else : print('No')
3Python3
{ "input": [ "4\nRRBR", "4\nBRBR", "4\nRBRR", "4\nBBRR", "4\nRRCR", "4\nRRAR", "4\nRARR", "4\nBQBR", "4\nRCRR", "4\nBPBR", "4\nRRRC", "4\nAQBR", "4\nRRRD", "4\nAQBS", "4\nDRRR", "4\nARBS", "4\nERRR", "4\nBQBS", "4\nBPBS", "4\nPBBS", "...
5ATCODER
p03080 ExaWizards 2019 - Red or Blue_1404
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat. Constraints * 1 \l...
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); String s = sc.next(); Main redOrBlue = new Main(); System.out.println(redOrBlue.judgeRedOrBlue(N, s)); } private String judgeRedOrBlue(int n, String s) {...
4JAVA
{ "input": [ "4\nRRBR", "4\nBRBR", "4\nRBRR", "4\nBBRR", "4\nRRCR", "4\nRRAR", "4\nRARR", "4\nBQBR", "4\nRCRR", "4\nBPBR", "4\nRRRC", "4\nAQBR", "4\nRRRD", "4\nAQBS", "4\nDRRR", "4\nARBS", "4\nERRR", "4\nBQBS", "4\nBPBS", "4\nPBBS", "...
5ATCODER
p03225 Tenka1 Programmer Contest - Equilateral_1405
There are some coins in the xy-plane. The positions of the coins are represented by a grid of characters with H rows and W columns. If the character at the i-th row and j-th column, s_{ij}, is `#`, there is one coin at point (i,j); if that character is `.`, there is no coin at point (i,j). There are no other coins in t...
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; int N, M, ps[3*MAXN][3*MAXN], ps2[3*MAXN][3*MAXN]; char arr[MAXN][MAXN]; vector<pair<int, int>> utama[2*MAXN], lain[2*MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for (int i = 0; i < N; i++) { for (int j = 0; j < M; ...
2C++
{ "input": [ "5 4\n#.##\n.##.\n#...\n..##\n...#", "13 27\n......#.........#.......#..\n...#.....###..\n..............#####...##...\n...#######......#...#######\n...#.....#.....###...#...#.\n...#######....#.#.#.#.###.#\n..............#.#.#...#.#..\n.#.#.#...###..\n...........#...#...#######\n..#######..#...#.....
5ATCODER
p03225 Tenka1 Programmer Contest - Equilateral_1406
There are some coins in the xy-plane. The positions of the coins are represented by a grid of characters with H rows and W columns. If the character at the i-th row and j-th column, s_{ij}, is `#`, there is one coin at point (i,j); if that character is `.`, there is no coin at point (i,j). There are no other coins in t...
H,W=map(int,input().split()) S=[list(input()) for i in range(H)] table=[[0]*(H+W-1) for i in range(H+W-1)] for j in range(H): for i in range(W): if S[j][i]=='#': table[i+j][i-j+H-1]=1 yoko=[[0]*(H+W) for i in range(H+W-1)] for j in range(H+W-1): for i in range(1,H+W): yoko[j][i]=...
3Python3
{ "input": [ "5 4\n#.##\n.##.\n#...\n..##\n...#", "13 27\n......#.........#.......#..\n...#.....###..\n..............#####...##...\n...#######......#...#######\n...#.....#.....###...#...#.\n...#######....#.#.#.#.###.#\n..............#.#.#...#.#..\n.#.#.#...###..\n...........#...#...#######\n..#######..#...#.....
5ATCODER
p03225 Tenka1 Programmer Contest - Equilateral_1407
There are some coins in the xy-plane. The positions of the coins are represented by a grid of characters with H rows and W columns. If the character at the i-th row and j-th column, s_{ij}, is `#`, there is one coin at point (i,j); if that character is `.`, there is no coin at point (i,j). There are no other coins in t...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class Main{ static void solve(){ int h = ni(), w=ni(); int H = w+h+1, W=h+w+1; int[][] cnt = new int[H][W]; int[][] cnty=new int[H][W]; long ans =0; Map<Integer, List<Integer> > ytox=new ...
4JAVA
{ "input": [ "5 4\n#.##\n.##.\n#...\n..##\n...#", "13 27\n......#.........#.......#..\n...#.....###..\n..............#####...##...\n...#######......#...#######\n...#.....#.....###...#...#.\n...#######....#.#.#.#.###.#\n..............#.#.#...#.#..\n.#.#.#...###..\n...........#...#...#######\n..#######..#...#.....
5ATCODER
p03371 AtCoder Beginner Contest 095 - Half and Half_1408
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the curr...
A, B, C, X, Y = [int(x) for x in raw_input().split()] s = 0 p = min(X, Y) X -= p Y -= p s += p * min(A+B, 2*C) s += X * min(A, 2*C) s += Y * min(B, 2*C) print s
1Python2
{ "input": [ "1500 2000 1600 3 2", "1500 2000 500 90000 100000", "1500 2000 1900 3 2", "1500 1572 1600 3 2", "1500 2445 500 90000 100000", "1500 2000 1615 3 2", "1500 1572 1600 0 2", "1500 2000 1166 3 2", "1500 651 1600 0 2", "1500 3132 752 90000 100000", "1500 2000 1343 3 ...
5ATCODER
p03371 AtCoder Beginner Contest 095 - Half and Half_1409
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the curr...
#include <iostream> #include <algorithm> using namespace std; int main(){ int A,B,C,X,Y,ans=0; cin >> A >> B >> C >> X >> Y; if(A+B<2*C){ ans=X*A+Y*B; }else{ ans=min(X,Y)*C*2+max(X-Y,0)*min(A,2*C)+max(Y-X,0)*min(B,2*C); } cout << ans << endl; }
2C++
{ "input": [ "1500 2000 1600 3 2", "1500 2000 500 90000 100000", "1500 2000 1900 3 2", "1500 1572 1600 3 2", "1500 2445 500 90000 100000", "1500 2000 1615 3 2", "1500 1572 1600 0 2", "1500 2000 1166 3 2", "1500 651 1600 0 2", "1500 3132 752 90000 100000", "1500 2000 1343 3 ...
5ATCODER
p03371 AtCoder Beginner Contest 095 - Half and Half_1410
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the curr...
a, b, c, x, y = map(int, input().split()) print(min(a*x+b*y, c*2*max(x,y), c*2*min(x,y)+abs(x-y)*(a if x>y else b)))
3Python3
{ "input": [ "1500 2000 1600 3 2", "1500 2000 500 90000 100000", "1500 2000 1900 3 2", "1500 1572 1600 3 2", "1500 2445 500 90000 100000", "1500 2000 1615 3 2", "1500 1572 1600 0 2", "1500 2000 1166 3 2", "1500 651 1600 0 2", "1500 3132 752 90000 100000", "1500 2000 1343 3 ...
5ATCODER
p03371 AtCoder Beginner Contest 095 - Half and Half_1411
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the curr...
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); long ans = 0; ...
4JAVA
{ "input": [ "1500 2000 1600 3 2", "1500 2000 500 90000 100000", "1500 2000 1900 3 2", "1500 1572 1600 3 2", "1500 2445 500 90000 100000", "1500 2000 1615 3 2", "1500 1572 1600 0 2", "1500 2000 1166 3 2", "1500 651 1600 0 2", "1500 3132 752 90000 100000", "1500 2000 1343 3 ...
5ATCODER
p03534 CODE FESTIVAL 2017 Final (Parallel) - Palindrome-phobia_1412
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
s = raw_input().strip() t = {c: 0 for c in "abc"} for c in s: t[c] += 1 print "YES" if max(t.values()) - min(t.values()) <= 1 else "NO"
1Python2
{ "input": [ "aba", "abac", "babacccabab", "acac", "bacaccbabab", "ccaa", "bacaacbcbab", "babcbcaacab", "bababccacab", "bacaccbabac", "bacaccbaaac", "caaabccacab", "caaaaccacab", "bacaccaaaac", "baa", "caba", "babacccbaab", "aacc", "bacabcbab...
5ATCODER
p03534 CODE FESTIVAL 2017 Final (Parallel) - Palindrome-phobia_1413
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
#include<bits/stdc++.h> using namespace std; int main(){ int a=0,b=0,c=0; string S; cin>>S; int n = S.length(); for(int i=0;i<n;i++){ int val = S[i] - 'a'; if(val==0) a++; if(val==1) b++; if(val==2) c++; } int ab = abs(a-b); int bc = abs(b-c); int ca = abs(c-a); if(ab<2 && bc<2 && c...
2C++
{ "input": [ "aba", "abac", "babacccabab", "acac", "bacaccbabab", "ccaa", "bacaacbcbab", "babcbcaacab", "bababccacab", "bacaccbabac", "bacaccbaaac", "caaabccacab", "caaaaccacab", "bacaccaaaac", "baa", "caba", "babacccbaab", "aacc", "bacabcbab...
5ATCODER
p03534 CODE FESTIVAL 2017 Final (Parallel) - Palindrome-phobia_1414
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
s=input() from collections import defaultdict d=defaultdict(int) for c in s: d[c]+=1 a,b,c=d["a"],d["b"],d["c"] mx=max(a,b,c) mn=min(a,b,c) #a,b,c = map(lambda x:x-mn, [a,b,c]) if mx-mn >=2: print("NO") else: print("YES")
3Python3
{ "input": [ "aba", "abac", "babacccabab", "acac", "bacaccbabab", "ccaa", "bacaacbcbab", "babcbcaacab", "bababccacab", "bacaccbabac", "bacaccbaaac", "caaabccacab", "caaaaccacab", "bacaccaaaac", "baa", "caba", "babacccbaab", "aacc", "bacabcbab...
5ATCODER
p03534 CODE FESTIVAL 2017 Final (Parallel) - Palindrome-phobia_1415
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int[] a = new int[3]; for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c == 'a') a[0] += 1; if(c == 'b') a[1] += 1; if(c ==...
4JAVA
{ "input": [ "aba", "abac", "babacccabab", "acac", "bacaccbabab", "ccaa", "bacaacbcbab", "babcbcaacab", "bababccacab", "bacaccbabac", "bacaccbaaac", "caaabccacab", "caaaaccacab", "bacaccaaaac", "baa", "caba", "babacccbaab", "aacc", "bacabcbab...
5ATCODER
p03694 AtCoder Beginner Contest 064 - Traveling AtCoDeer Problem_1416
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and ...
n = input() houses = map(lambda x: int(x), raw_input().split()) houses = sorted(list(set(houses))) print houses[-1] - houses[0]
1Python2
{ "input": [ "4\n2 3 7 9", "8\n3 1 4 1 5 9 2 6", "4\n2 3 9 9", "8\n3 1 4 1 5 18 2 6", "4\n2 3 13 9", "4\n4 4 13 9", "8\n3 1 1 1 5 15 1 6", "4\n4 4 8 9", "4\n0 4 8 18", "8\n1 1 1 2 5 14 1 6", "4\n-1 2 4 18", "4\n-1 2 4 31", "8\n0 1 0 2 7 8 1 6", "4\n-1 2 11 6", ...
5ATCODER
p03694 AtCoder Beginner Contest 064 - Traveling AtCoDeer Problem_1417
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and ...
#include <iostream> #include <algorithm> using namespace std; int main(){ int n,k[1000]; cin>>n; for(int i=0;i<n;i++){ cin>>k[i]; } sort(k,k+n); cout<<k[n-1]-k[0]<<endl; }
2C++
{ "input": [ "4\n2 3 7 9", "8\n3 1 4 1 5 9 2 6", "4\n2 3 9 9", "8\n3 1 4 1 5 18 2 6", "4\n2 3 13 9", "4\n4 4 13 9", "8\n3 1 1 1 5 15 1 6", "4\n4 4 8 9", "4\n0 4 8 18", "8\n1 1 1 2 5 14 1 6", "4\n-1 2 4 18", "4\n-1 2 4 31", "8\n0 1 0 2 7 8 1 6", "4\n-1 2 11 6", ...
5ATCODER
p03694 AtCoder Beginner Contest 064 - Traveling AtCoDeer Problem_1418
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and ...
num = input() l = list(map(int, input().split())) print(max(l) - min(l))
3Python3
{ "input": [ "4\n2 3 7 9", "8\n3 1 4 1 5 9 2 6", "4\n2 3 9 9", "8\n3 1 4 1 5 18 2 6", "4\n2 3 13 9", "4\n4 4 13 9", "8\n3 1 1 1 5 15 1 6", "4\n4 4 8 9", "4\n0 4 8 18", "8\n1 1 1 2 5 14 1 6", "4\n-1 2 4 18", "4\n-1 2 4 31", "8\n0 1 0 2 7 8 1 6", "4\n-1 2 11 6", ...
5ATCODER
p03694 AtCoder Beginner Contest 064 - Traveling AtCoDeer Problem_1419
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and ...
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner cin = new Scanner(System.in); int A = cin.nextInt(); int list[] = new int[A]; int tmp; for(int i=0;i<A;i++){ list[i] = cin.nextInt(); } Arrays.sort(list); tmp = list[0]; int s...
4JAVA
{ "input": [ "4\n2 3 7 9", "8\n3 1 4 1 5 9 2 6", "4\n2 3 9 9", "8\n3 1 4 1 5 18 2 6", "4\n2 3 13 9", "4\n4 4 13 9", "8\n3 1 1 1 5 15 1 6", "4\n4 4 8 9", "4\n0 4 8 18", "8\n1 1 1 2 5 14 1 6", "4\n-1 2 4 18", "4\n-1 2 4 31", "8\n0 1 0 2 7 8 1 6", "4\n-1 2 11 6", ...
5ATCODER
p03849 AtCoder Regular Contest 066 - Xor Sum_1420
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7. Constraints * 1≦N≦10^{18...
N = input() MOD = 10**9+7 memo = {0: 1, 1: 2} def S(k): if k in memo: return memo[k] if k % 2 == 1: result = (2*S(k/2) + S(k/2-1)) % MOD else: result = (S(k/2) + 2*S(k/2-1)) % MOD memo[k] = result return result print S(N)
1Python2
{ "input": [ "3", "1422", "1000000000000000000", "4", "1026", "1000000001000000000", "0", "530", "1100000001000000000", "1", "706", "1100000001000010000", "2", "152", "1100000001001010000", "7", "192", "1100000011001010000", "5", "292", ...
5ATCODER
p03849 AtCoder Regular Contest 066 - Xor Sum_1421
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7. Constraints * 1≦N≦10^{18...
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b)%MOD; } int nth_bit(int64_t num , int n) { return (num >> n) & 1; } int main() { int64_t N; cin >> N; int64_t dp[61][3] = {0}; dp[60][0] = 1; for(int d = 59; d >= 0; d--) {...
2C++
{ "input": [ "3", "1422", "1000000000000000000", "4", "1026", "1000000001000000000", "0", "530", "1100000001000000000", "1", "706", "1100000001000010000", "2", "152", "1100000001001010000", "7", "192", "1100000011001010000", "5", "292", ...
5ATCODER
p03849 AtCoder Regular Contest 066 - Xor Sum_1422
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7. Constraints * 1≦N≦10^{18...
n=int(input()) d=dict() def get(n): if(n==1):return 1 if(n==0):return 0 if(n in d.keys()):return d[n] if(n%2==0): d[n]=2*get(n//2)+get(n//2-1) else: d[n]=2*get(n//2)+get(n//2+1) d[n]%=(10**9+7) return d[n] def check(u,v,n): for a in range(n+1): b=u ^ a if(...
3Python3
{ "input": [ "3", "1422", "1000000000000000000", "4", "1026", "1000000001000000000", "0", "530", "1100000001000000000", "1", "706", "1100000001000010000", "2", "152", "1100000001001010000", "7", "192", "1100000011001010000", "5", "292", ...
5ATCODER
p03849 AtCoder Regular Contest 066 - Xor Sum_1423
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7. Constraints * 1≦N≦10^{18...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * @author Pavel Mavrin */ public class Main { private static final long MOD = (long) (1e9 + 7); private void solve() throws IOException { long n = Long.pa...
4JAVA
{ "input": [ "3", "1422", "1000000000000000000", "4", "1026", "1000000001000000000", "0", "530", "1100000001000000000", "1", "706", "1100000001000010000", "2", "152", "1100000001001010000", "7", "192", "1100000011001010000", "5", "292", ...
5ATCODER
p04015 AtCoder Regular Contest 060 - Tak and Cards_1424
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_...
import bisect import sys import math import itertools sys.setrecursionlimit(10000) INF = float('inf') # input macro def i(): return int(raw_input()) def ii(): return map(int,raw_input().split(" ")) def s(): return raw_input() def ss(): return raw_input().split(" ") def slist(): return list(raw_inp...
1Python2
{ "input": [ "4 8\n7 9 8 9", "3 8\n6 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "8 5\n3 6 2 8 7 6 5 9", "4 8\n7 12 8 9", "3 8\n9 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3", "8 5\n3 6 2 8 7 2 5 9", "3 8\n15 6...
5ATCODER
p04015 AtCoder Regular Contest 060 - Tak and Cards_1425
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_...
#include <cstdio> #include <algorithm> using namespace std; long long int knapsack[51][3000]={}; long long int ans=0; int main(){ int n,a,t; knapsack[0][0]=1; scanf("%d %d",&n,&a); for(int i=1;i<=n;i++){ scanf("%d",&t); for(int k=i-1;k>=0;k--){ for(int j=2500;j>=t;j--){ knapsack[k+1][j]+=knapsack[k][j-t]...
2C++
{ "input": [ "4 8\n7 9 8 9", "3 8\n6 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "8 5\n3 6 2 8 7 6 5 9", "4 8\n7 12 8 9", "3 8\n9 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3", "8 5\n3 6 2 8 7 2 5 9", "3 8\n15 6...
5ATCODER
p04015 AtCoder Regular Contest 060 - Tak and Cards_1426
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_...
n,a=map(int,input().split()) X=list(map(int,input().split())) dp=[[[0]*(sum(X)+1) for _ in range(n+1)] for _ in range(n+1)] dp[0][0][0]=1 for i in range(1,n+1): #x_1,x_2...x_n for k in range(i): #k枚数選ぶ for s in range(sum(X)+1): #合計 if dp[i-1][k][s]: dp[i][k+1][s+X[i-1]]+=dp[i-1][k][s] #1枚選択肢が増え...
3Python3
{ "input": [ "4 8\n7 9 8 9", "3 8\n6 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "8 5\n3 6 2 8 7 6 5 9", "4 8\n7 12 8 9", "3 8\n9 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3", "8 5\n3 6 2 8 7 2 5 9", "3 8\n15 6...
5ATCODER
p04015 AtCoder Regular Contest 060 - Tak and Cards_1427
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_...
import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.PriorityQueue; import java.util.Scanner; import java.util.TreeSet; import java.lang.Object; public class Main { Scanne...
4JAVA
{ "input": [ "4 8\n7 9 8 9", "3 8\n6 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "8 5\n3 6 2 8 7 6 5 9", "4 8\n7 12 8 9", "3 8\n9 6 9", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3", "8 5\n3 6 2 8 7 2 5 9", "3 8\n15 6...
5ATCODER
p00100 Sale Result_1428
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the program should print IDs of employees whose total sales proceeds ...
while True: n = int(raw_input()) if n == 0: break data = {} order = [] for i in range(n): id,price,quant = map(int, raw_input().split()) if id in data: data[id] += price*quant else: data[id] = price*quant order.append(id) if max(data.values()) < 1000000: print "NA" else: for k in order: ...
1Python2
{ "input": [ "4\n1001 2000 520\n1002 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n1001 2000 520\n80 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n0001 2000 520\n80 1800 450\n1...
6AIZU
p00100 Sale Result_1429
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the program should print IDs of employees whose total sales proceeds ...
#include<iostream> #include<vector> #include<cstring> #include<algorithm> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n; while( cin >> n, n ){ long long emp[4001]; vector<int> nums; bool exist = false; memset( emp, 0, sizeof(emp) ); rep(i,n){ int num; long long val, am...
2C++
{ "input": [ "4\n1001 2000 520\n1002 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n1001 2000 520\n80 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n0001 2000 520\n80 1800 450\n1...
6AIZU
p00100 Sale Result_1430
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the program should print IDs of employees whose total sales proceeds ...
while True: try: n=int(input()) except: break if n==0: break data={} staff=[] for i in range(n): spam=list(map(int,input().split())) if spam[0] in data.keys(): data[spam[0]]+=spam[1]*spam[2] else: data[spam[0]]=spam[1]*spam[...
3Python3
{ "input": [ "4\n1001 2000 520\n1002 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n1001 2000 520\n80 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n0001 2000 520\n80 1800 450\n1...
6AIZU
p00100 Sale Result_1431
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the program should print IDs of employees whose total sales proceeds ...
import java.io.*; import java.util.*; public class Main{ public static void main(String args[]){ try{ new Main(); }catch(IOException err){ err.printStackTrace(); } } public Main() throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); List<Integer> Ans = new ...
4JAVA
{ "input": [ "4\n1001 2000 520\n1002 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n1001 2000 520\n80 1800 450\n1003 1600 625\n1001 200 1220\n2\n1001 100 3\n1005 1000 100\n2\n2013 5000 100\n2013 5000 100\n0", "4\n0001 2000 520\n80 1800 450\n1...
6AIZU
p00232 Life Game_1432
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the piec...
while True: x, y, z = map(int, raw_input().split()) if x==0 and y==0 and z==0: break dp = [[0.0 for col in range(5101)] for row in range(61)] m = {} for i in range(y+10): m[i] = (0,0) v = [] v = map(int, raw_input().split()) for i in range(z): n, e, a = map(int, raw_input...
1Python2
{ "input": [ "1 2 0\n1\n1 2 1\n1\n1 2 100\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1...
6AIZU
p00232 Life Game_1433
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the piec...
#include <bits/stdc++.h> using namespace std; double mem[51][5001]; int x,y,z,v[100],used[51][5001]; struct po{int e,a;}; po E[101]; double dfs(int pos,int mo){ if(pos==y) return mo; if(used[pos][mo]) return mem[pos][mo]; used[pos][mo]=1; for(int i=0;i<x;i++) { int npos=min(y,pos+v[i]),nmo=mo; int e...
2C++
{ "input": [ "1 2 0\n1\n1 2 1\n1\n1 2 100\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1...
6AIZU
p00232 Life Game_1434
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the piec...
from heapq import heappush, heappop def main(): while True: x, y, z = map(int, input().split()) if x == 0:break vlst = list(map(int, input().split())) events = {} for _ in range(z): n, e, a = map(int, input().split()) events[n] = (e, a) que = [] heappush(que, (0, 0)) ...
3Python3
{ "input": [ "1 2 0\n1\n1 2 1\n1\n1 2 100\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1...
6AIZU
p00232 Life Game_1435
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the piec...
import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOEx...
4JAVA
{ "input": [ "1 2 0\n1\n1 2 1\n1\n1 2 100\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1 2\n1 2 100\n4 5 3\n1 2 3 4\n1 1 2\n2 2 100\n4 3 60\n0 0 0", "1 2 0\n1\n1 2 1\n1\n1 2 101\n1 2 1\n2\n1 2 100\n2 2 1\n1...
6AIZU
p00395 Maze and Items_1436
Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items. The objectiv...
#include <iostream> #include <queue> using namespace std; int H, W, sx[32], sy[32], s[10][10], idx[1009][1009]; char c[1009][1009]; int t[32][32], u[1009][1009]; pair<int, int> dp[1 << 10][32]; int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, 1, 0, -1 }; int main() { cin >> W >> H; for (int i = 1; i <= H; i++) { fo...
2C++
{ "input": [ "12 5\n.....S......\n.abcdefghij.\n.0123456789.\n.ABCDEFGHIJ.\n.....T......\n0 1 0 0 0 0 0 0 0 0\n2 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "5 6\n..S...
6AIZU
p00610 Cleaning Robot 2_1437
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
def checkback(B,i,j): samesum= (B[i][j]==B[i][j-1]) +(B[i][j]==B[i][j+1]) +(B[i][j]==B[i-1][j]) if samesum==2: return not B[i][j] else: return B[i][j] while(1): [N,K]=map(int,raw_input().split()) if N==0: break if N%2 or K>2**(N/2): print "No\n" else: ...
1Python2
{ "input": [ "2 1\n2 3\n6 4\n0 0", "3 1\n2 3\n6 4\n0 0", "4 1\n2 3\n6 4\n0 0", "3 1\n4 3\n6 4\n0 0", "4 1\n1 3\n6 6\n0 0", "5 1\n4 3\n6 6\n0 0", "8 1\n1 3\n6 6\n0 0", "5 1\n4 3\n12 4\n0 0", "8 1\n1 3\n2 6\n0 0", "5 1\n4 3\n23 4\n0 0", "16 1\n1 3\n2 6\n0 0", "19 1\n1 3\n...
6AIZU
p00610 Cleaning Robot 2_1438
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
#include<iostream> #include<string> #define MAX 64 using namespace std; int main() { while(true){ long long int N; long long int K; bool tile[MAX+2][MAX+2]; cin >> N >> K; if( N == 0 && K == 0 ) break; if( K>(1LL<<(N/2)) || N%2==1 ){ cout << "No\n" << endl; continue; } --K; for(long lo...
2C++
{ "input": [ "2 1\n2 3\n6 4\n0 0", "3 1\n2 3\n6 4\n0 0", "4 1\n2 3\n6 4\n0 0", "3 1\n4 3\n6 4\n0 0", "4 1\n1 3\n6 6\n0 0", "5 1\n4 3\n6 6\n0 0", "8 1\n1 3\n6 6\n0 0", "5 1\n4 3\n12 4\n0 0", "8 1\n1 3\n2 6\n0 0", "5 1\n4 3\n23 4\n0 0", "16 1\n1 3\n2 6\n0 0", "19 1\n1 3\n...
6AIZU
p00610 Cleaning Robot 2_1439
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
# AOJ 1024 Cleaning Robot 2.0 # Python3 2018.7.5 bal4u mv = ((-1,0), (0,1), (1,0), (0,-1)) d2c = {0:'.', 1:'E'} while True: n, k = map(int, input().split()) if n == 0: break k, n1 = k-1, n-1 if (n & 1) or k >= (1<<(n>>1)): print("No\n") continue arr = [[-1 for c in range(n)] for r in range(n)] for c in rang...
3Python3
{ "input": [ "2 1\n2 3\n6 4\n0 0", "3 1\n2 3\n6 4\n0 0", "4 1\n2 3\n6 4\n0 0", "3 1\n4 3\n6 4\n0 0", "4 1\n1 3\n6 6\n0 0", "5 1\n4 3\n6 6\n0 0", "8 1\n1 3\n6 6\n0 0", "5 1\n4 3\n12 4\n0 0", "8 1\n1 3\n2 6\n0 0", "5 1\n4 3\n23 4\n0 0", "16 1\n1 3\n2 6\n0 0", "19 1\n1 3\n...
6AIZU
p00610 Cleaning Robot 2_1440
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { while (true) { int N = sc.nextInt(); long K = sc.nextLong(); if (N == 0 && K == 0) break; solve(N, K); } } static void solve(int N, long K) { if (...
4JAVA
{ "input": [ "2 1\n2 3\n6 4\n0 0", "3 1\n2 3\n6 4\n0 0", "4 1\n2 3\n6 4\n0 0", "3 1\n4 3\n6 4\n0 0", "4 1\n1 3\n6 6\n0 0", "5 1\n4 3\n6 6\n0 0", "8 1\n1 3\n6 6\n0 0", "5 1\n4 3\n12 4\n0 0", "8 1\n1 3\n2 6\n0 0", "5 1\n4 3\n23 4\n0 0", "16 1\n1 3\n2 6\n0 0", "19 1\n1 3\n...
6AIZU
p00748 Pollock's conjecture_1441
The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+...
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9+7; template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b)||1 : 0); } int main(){ vector<int> d,e; for(int i=1; i<=200; i++){ int m = i*(i+1)*(i+2)/6; d.push_back(m); if(m%2) e.push_back(m); } vector<int> dp1...
2C++
{ "input": [ "40\n14\n5\n165\n120\n103\n106\n139\n0", "40\n14\n5\n165\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n150\n0", "40\n14\n5\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n72\n133\n106\n150\n...
6AIZU
p00748 Pollock's conjecture_1442
The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+...
def main(): INIT = 100 query = [] ans = [] while True: q = int(input()) if q == 0: break query.append(q) MAX = max(query) table = [INIT] * (MAX + 1) table[0] = 0 all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] odd_item = [i for i in all_item if i % 2] eve_item ...
3Python3
{ "input": [ "40\n14\n5\n165\n120\n103\n106\n139\n0", "40\n14\n5\n165\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n150\n0", "40\n14\n5\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n72\n133\n106\n150\n...
6AIZU
p00748 Pollock's conjecture_1443
The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+...
import java.util.Arrays; import java.util.Scanner; public class Main { static int[] simen=new int[1000]; static int[] kisu_simen=new int[48]; static int INF=1000000007; public static void main(String[] args) { for(int i=0; i<200; i++) { int tmp=(i+1)*(i+2)*(i+3)/6; for(int j=0; j<5; j++) { simen[i*5+j]...
4JAVA
{ "input": [ "40\n14\n5\n165\n120\n103\n106\n139\n0", "40\n14\n5\n165\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n150\n0", "40\n14\n5\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n72\n133\n106\n150\n...
6AIZU
p00886 Towns along a Highway_1444
There are several towns on a highway. The highway has no forks. Given the distances between the neighboring towns, we can calculate all distances from any town to others. For example, given five towns (A, B, C, D and E) and the distances between neighboring towns like in Figure C.1, we can calculate the distance matrix...
#include<stdio.h> #include<algorithm> #include<vector> #include<set> using namespace std; int d[310]; int c[510]; int v[310]; int at[30]; int n; int tmp[30]; int sz; set<vector<int> >S; inline int ABS(int a){return max(a,-a);} void solve(int a,int b){ if(a==n){ for(int i=0;i<n;i++)tmp[i]=at[i]; std::sort(tmp,tm...
2C++
{ "input": [ "2\n1\n3\n5 3 2\n3\n6 3 2\n5\n9 8 7 6 6 4 3 2 2 1\n6\n9 8 8 7 6 6 5 5 3 3 3 2 2 1 1\n6\n11 10 9 8 7 6 6 5 5 4 3 2 2 1 1\n7\n72 65 55 51 48 45 40 38 34 32 27 25 24 23 21 17 14 13 11 10 7\n20\n190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171\n170 169 168 167 166 165 164 1...
6AIZU
p00886 Towns along a Highway_1445
There are several towns on a highway. The highway has no forks. Given the distances between the neighboring towns, we can calculate all distances from any town to others. For example, given five towns (A, B, C, D and E) and the distances between neighboring towns like in Figure C.1, we can calculate the distance matrix...
import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } static int N; static int[] d; static int[] cnt; static int[] ans; static int L; static ArrayList<int[]> ansLis; void run() {...
4JAVA
{ "input": [ "2\n1\n3\n5 3 2\n3\n6 3 2\n5\n9 8 7 6 6 4 3 2 2 1\n6\n9 8 8 7 6 6 5 5 3 3 3 2 2 1 1\n6\n11 10 9 8 7 6 6 5 5 4 3 2 2 1 1\n7\n72 65 55 51 48 45 40 38 34 32 27 25 24 23 21 17 14 13 11 10 7\n20\n190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171\n170 169 168 167 166 165 164 1...
6AIZU
p01017 Yu-kun Likes Rectangles_1446
Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangles as much as programming. Yu-kun decided to write a program to calculate the maximum score that can be obtained, thinking of a new play to ge...
#include <iostream> #include <cstdio> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) #define REP1(i,n) for(int i=1;i<=n;++i) #define ALL(c) (c).begin(),(c).end() int a[50][50],b[50][50],c[50][50]; int main(){ int ha,wa,hc,wc; cin >> ha >> wa; rep(i,ha) rep(j,wa) cin >> a[i][j]; rep(i,ha) rep(j,wa) cin >...
2C++
{ "input": [ "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 1 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "3 4\n4 1 9 1\n9 1 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "3 3\n5 1 3\n2 5 9\n0 1 5\n1 0 0\n0 1 1\n0 1 1\n1 1\n1", "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11...
6AIZU
p01017 Yu-kun Likes Rectangles_1447
Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangles as much as programming. Yu-kun decided to write a program to calculate the maximum score that can be obtained, thinking of a new play to ge...
H, W = map(int, input().split()) a_mp = [list(map(int, input().split())) for _ in range(H)] b_mp = [list(map(int, input().split())) for _ in range(H)] h, w = map(int, input().split()) c_mp = [list(map(int, input().split())) for _ in range(h)] INF = 10 ** 20 def check(x, y): ret = 0 for dy in range(h): for dx ...
3Python3
{ "input": [ "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 1 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "3 4\n4 1 9 1\n9 1 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "3 3\n5 1 3\n2 5 9\n0 1 5\n1 0 0\n0 1 1\n0 1 1\n1 1\n1", "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11...
6AIZU
p01017 Yu-kun Likes Rectangles_1448
Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangles as much as programming. Yu-kun decided to write a program to calculate the maximum score that can be obtained, thinking of a new play to ge...
import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new Problem_B(); } class Problem_B{ int h,w,ph,pw; int[][] a; boolean[][] b; boolean[][] c; int sum(int start_x,int start_y){ int result = 0; f...
4JAVA
{ "input": [ "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 1 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "3 4\n4 1 9 1\n9 1 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "3 3\n5 1 3\n2 5 9\n0 1 5\n1 0 0\n0 1 1\n0 1 1\n1 1\n1", "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11...
6AIZU
p01150 Eight Princes_1449
Once upon a time in a kingdom far, far away, there lived eight princes. Sadly they were on very bad terms so they began to quarrel every time they met. One day, the princes needed to seat at the same round table as a party was held. Since they were always in bad mood, a quarrel would begin whenever: * A prince took t...
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; int sum=0; vector<int> solve(bitset<13>&used, vector<int>&nums) { if (used.count() == 13) { return vector<int>{-1}; } else { for (int i = 0; i < 13; ++i) { if (!used[i]) { if (sum ...
2C++
{ "input": [ "8\n16\n17\n0", "8\n6\n17\n0", "8\n23\n17\n0", "8\n6\n3\n0", "8\n0\n17\n0", "8\n30\n17\n0", "8\n6\n23\n0", "8\n23\n33\n0", "8\n1\n0\n0", "8\n30\n24\n0", "8\n6\n21\n0", "8\n40\n33\n0", "8\n15\n33\n0", "8\n5\n25\n0", "8\n23\n2\n0", "8\n39\n33\...
6AIZU
p01289 Strange Couple_1450
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undir...
#include <cmath> #include <queue> #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> using namespace std; typedef pair<int, int> pii; const int maxn = 105; const int inf = 1e9; const double eps = 1e-12; int n, s, t, flag[maxn]; vector<pii> mp[maxn]; void add_edge(int u, ...
2C++
{ "input": [ "5 1 5\n1 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n0 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 ...
6AIZU
p01289 Strange Couple_1451
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undir...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 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 lis...
3Python3
{ "input": [ "5 1 5\n1 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n0 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 ...
6AIZU
p01289 Strange Couple_1452
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undir...
import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Main { private static final Scanner IN = new Scanner(System.in); private static final int INFINITE = Integer.MAX_VALUE >> 4; private static final int MAX_N = 100; private final int[] distance = new int[MAX_N]; pr...
4JAVA
{ "input": [ "5 1 5\n1 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n0 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 ...
6AIZU
p01458 Kth Sentence_1453
A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m. Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K-th sentence among the candidates sorted i...
//84104971101048411497 - Can you guess what does this mean? #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef complex<double> point; #define mapii map<int, int> #define debug(a) cout << #a << ": " << a << endl #define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl #define fd...
2C++
{ "input": [ "3 3 6\na\naa\nb", "2 10 2\nhello\nworld", "2 59 1000000000000000000\na\nb", "3 3 4\na\naa\nb", "3 3 4\nb\naa\nb", "3 3 1\na\naa\nb", "2 10 0\nhello\nworld", "2 67 1000000000000000000\na\nb", "3 3 4\nc\naa\nb", "2 12 0\nhello\nworld", "2 132 1000000000000000000...
6AIZU
p01458 Kth Sentence_1454
A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m. Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K-th sentence among the candidates sorted i...
import java.io.IOException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; class Main { public static void main(String[] args) throws IOException { new Main().run(); } long INF = (long) (1e19); void run() { Scanner s...
4JAVA
{ "input": [ "3 3 6\na\naa\nb", "2 10 2\nhello\nworld", "2 59 1000000000000000000\na\nb", "3 3 4\na\naa\nb", "3 3 4\nb\naa\nb", "3 3 1\na\naa\nb", "2 10 0\nhello\nworld", "2 67 1000000000000000000\na\nb", "3 3 4\nc\naa\nb", "2 12 0\nhello\nworld", "2 132 1000000000000000000...
6AIZU
p01609 One_1455
One Problem Statement A beautiful mountain range can be seen from the train window. The window is a rectangle with the coordinates of the lower left corner (0, 0) and the coordinates of the upper right corner (W, H). N peaks can be seen from the window, and the i-th peak has the shape of an upwardly convex parabola y...
#include <cstdio> #include <cmath> #include <vector> #include <algorithm> using namespace std; #define INTERVAL 2097152 #define EPS 1e-9 int W,H,N; int yama[101][3]; double xint[101][2]; double quad(double x,int nyama) { double a=yama[nyama][0]; double p=yama[nyama][1]; double q=yama[nyama][2]; return a*(x-p)*...
2C++
{ "input": [ "20 20 2\n-1 10 10\n-2 10 5", "15 100 2\n-2 5 100\n-2 10 100", "20 20 1\n-1 10 10", "20 20 2\n-1 10 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 3", "20 28 1\n-2 15 10", "20 28 1\n-2 15 16", "13 20 2\n-1 10 10\n-2 10 5", "20 20 2\n-1 10 7\n...
6AIZU
p01609 One_1456
One Problem Statement A beautiful mountain range can be seen from the train window. The window is a rectangle with the coordinates of the lower left corner (0, 0) and the coordinates of the upper right corner (W, H). N peaks can be seen from the window, and the i-th peak has the shape of an upwardly convex parabola y...
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main{ Scanner sc=new Scanner(System.in); int INF=1<<28; int w, h, n; double[] as, ps, qs; void run(){ w=sc.nextI...
4JAVA
{ "input": [ "20 20 2\n-1 10 10\n-2 10 5", "15 100 2\n-2 5 100\n-2 10 100", "20 20 1\n-1 10 10", "20 20 2\n-1 10 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 3", "20 28 1\n-2 15 10", "20 28 1\n-2 15 16", "13 20 2\n-1 10 10\n-2 10 5", "20 20 2\n-1 10 7\n...
6AIZU
p01770 Arojam's Mask_1457
Problem statement You are a hero. The world in which the hero is traveling consists of N cities and M roads connecting different cities. Road i connects town a_i and town b_i and can move in both directions. The purpose of the brave is to start from town S and move to town T. S and T are different cities. The hero ca...
#include<bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) using namespace std; typedef pair<int,int>P; typedef pair<P,P>P2; int dp[111][111][1<<5]; int n,m,e,s,t,r; vector<P>v[100000]; signed main(){ r(i,111)r(j,1<<5)r(k,111)dp[i][k][j]=1e9; cin>>n>>m>>e>>s>>t>>r; r(i,m){ int a,b; cin>>a>>b; v[a...
2C++
{ "input": [ "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 2\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 5 5\n0 2\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 3 ...
6AIZU
p01770 Arojam's Mask_1458
Problem statement You are a hero. The world in which the hero is traveling consists of N cities and M roads connecting different cities. Road i connects town a_i and town b_i and can move in both directions. The purpose of the brave is to start from town S and move to town T. S and T are different cities. The hero ca...
from collections import deque n, m, e, s, t, r = map(int, input().split()) edges = [[] for _ in range(n * 2 ** e)] for _ in range(m): a, b = map(int, input().split()) for i in range(2 ** e): edges[a + n * i].append(b + n * i) edges[b + n * i].append(a + n * i) start = s slide = {} for i in range(e): a, ...
3Python3
{ "input": [ "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 2\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 5 5\n0 2\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 3 ...
6AIZU
p01770 Arojam's Mask_1459
Problem statement You are a hero. The world in which the hero is traveling consists of N cities and M roads connecting different cities. Road i connects town a_i and town b_i and can move in both directions. The purpose of the brave is to start from town S and move to town T. S and T are different cities. The hero ca...
import java.util.PriorityQueue; import java.util.Scanner; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new RitProE().doIt(); } class RitProE{ int n,m,e,start,end,days; boolean[][] map; int[][] eventMap; int[] a,b,c; ...
4JAVA
{ "input": [ "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 2\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 5 5\n0 2\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 3 ...
6AIZU
p01904 Minimum Enclosing Rectangle_1460
G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle- story Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICPC2010 in this front activity, but the problem at that time was difficult. ...
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) c...
2C++
{ "input": [ "1", "001", "001" ], "output": [ "1", "1.000000000\n", "1.000000000\n" ] }
6AIZU
p01904 Minimum Enclosing Rectangle_1461
G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle- story Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICPC2010 in this front activity, but the problem at that time was difficult. ...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { static int[] D = {1,0,-1,0}; public static void main(String[] args) { IO io ...
4JAVA
{ "input": [ "1", "001", "001" ], "output": [ "1", "1.000000000\n", "1.000000000\n" ] }
6AIZU
p02042 ABSum_1462
problem Given a sequence $ A $ of length $ N $. You can swap the $ i $ th and $ j $ th ($ 0 \ leq i, j \ leq N-1 $) elements of a sequence up to $ M $ times. Find the maximum value of $ \ sum_ {i = 0} ^ {N -1} abs (A_i --i) $ in the sequence created by the operation. output Find the maximum value of $ \ sum_ {i =...
#include<iomanip> #include<limits> #include<thread> #include<utility> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> #include<cassert> #include<random> #include<chrono> #include<unordered_set> #includ...
2C++
{ "input": [ "5 2\n0 3 2 1 4", "5 2\n0 1 2 1 4", "5 2\n0 1 0 1 0", "5 2\n0 1 0 1 -1", "5 3\n-1 1 0 2 -1", "2 2\n0 1 2 1 4", "1 2\n0 1 0 1 0", "4 3\n0 1 0 2 -1", "2 3\n-1 1 0 2 -1", "2 3\n-2 1 0 2 -1", "5 2\n0 0 4 1 4", "5 2\n0 0 4 2 4", "2 3\n0 0 -1 2 -1", "9 1\...
6AIZU
p02185 Many Decimal Integers_1463
D: Many Decimal Integers problem Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length. Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be ...
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; //const int MOD=998244353; const int INF=1e9; const long long LINF=1e18; #define int long long //template template <typename T> void fin(T a){ cout<<a<<endl; exit(0); } int pw(int n,int k){ if(k<0)return pw(n,k+MOD-1); int res=1; while(k){ ...
2C++
{ "input": [ "73\n6?", "73\n?6", "73\n@6", "73\n5?", "73\n?5", "73\n4?", "73\n?4", "73\n?8", "73\n?7", "73\n7?", "73\n?3", "73\n3?", "73\n?9", "73\n?2", "73\n70", "73\n1?", "73\n27", "73\n?1", "73\n49", "73\n72", "73\n59", "73\n?0...
6AIZU
p02185 Many Decimal Integers_1464
D: Many Decimal Integers problem Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length. Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be ...
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()]...
3Python3
{ "input": [ "73\n6?", "73\n?6", "73\n@6", "73\n5?", "73\n?5", "73\n4?", "73\n?4", "73\n?8", "73\n?7", "73\n7?", "73\n?3", "73\n3?", "73\n?9", "73\n?2", "73\n70", "73\n1?", "73\n27", "73\n?1", "73\n49", "73\n72", "73\n59", "73\n?0...
6AIZU
p02327 Largest Rectangle_1465
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following...
h, w = map(int, raw_input().split()) c = [map(int, raw_input().split()) for i in xrange(h)] cnt = [[0]*w for i in xrange(h)] for j in xrange(w): seq = 0 for i in xrange(h): if c[i][j] == 0: seq += 1 else: seq = 0 cnt[i][j] = seq ans = 0 st = [(0, -1)] for i in xr...
1Python2
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "0 5\n0 0 1 -1 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "1 5\n1 0 1 0 1\n2 0 -1 0...
6AIZU
p02327 Largest Rectangle_1466
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following...
#include<bits/stdc++.h> const static int MAX = 1400; int H, W; int buffer[MAX][MAX]; int T[MAX][MAX]; struct Rectangle{ int height; int pos; }; int getLargestRectangle(int size, int buffer[]){ std::stack<Rectangle> S; int maxv = 0; buffer[size] = 0; for(int i = 0; i <= size; i++){ Re...
2C++
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "0 5\n0 0 1 -1 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "1 5\n1 0 1 0 1\n2 0 -1 0...
6AIZU
p02327 Largest Rectangle_1467
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following...
H, W = map(int, input().split()) height = W * [0] max_area = 0 for _ in range(H): height = [0 if t else height[j]+1 for j, t in enumerate(map(int, input().split()))] height.append(0) stack = [] for i, h in enumerate(height): if stack: if stack[-1][1] == h: continue ...
3Python3
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "0 5\n0 0 1 -1 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "1 5\n1 0 1 0 1\n2 0 -1 0...
6AIZU
p02327 Largest Rectangle_1468
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.LinkedList; import java.util.Scanner; public class Main { static boolean debug = false; public static void main(String[] args) throws IOException { UserScanner scan = new UserScanner(System.in); PrintWriter pwr...
4JAVA
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "0 5\n0 0 1 -1 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "1 5\n1 0 1 0 1\n2 0 -1 0...
6AIZU
p02472 Addition of Big Integers_1469
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 S...
a=raw_input().split() print(int(a[0])+int(a[1]))
1Python2
{ "input": [ "5 8", "9 8", "17 8", "17 12", "17 16", "21 16", "41 16", "58 16", "58 30", "109 30", "195 30", "302 30", "552 30", "47 30", "87 30", "87 37", "139 37", "139 39", "107 39", "107 73", "107 60", "107 79", "107 51", ...
6AIZU
p02472 Addition of Big Integers_1470
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 S...
#include<stdio.h> #include<cmath> #include<string.h> #include<algorithm> #include<vector> #include<iostream> using namespace std; #define MAX 3000000 #define MAXN 9999 #define MAXSIZE (100005/2) #define DLEN 4 class BigNum{ public: int a[100005/2]; int len; BigNum(){len=1,memset(a,0,sizeof(a));} BigN...
2C++
{ "input": [ "5 8", "9 8", "17 8", "17 12", "17 16", "21 16", "41 16", "58 16", "58 30", "109 30", "195 30", "302 30", "552 30", "47 30", "87 30", "87 37", "139 37", "139 39", "107 39", "107 73", "107 60", "107 79", "107 51", ...
6AIZU
p02472 Addition of Big Integers_1471
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 S...
n, m = map(int, input().split()) print(n + m)
3Python3
{ "input": [ "5 8", "9 8", "17 8", "17 12", "17 16", "21 16", "41 16", "58 16", "58 30", "109 30", "195 30", "302 30", "552 30", "47 30", "87 30", "87 37", "139 37", "139 39", "107 39", "107 73", "107 60", "107 79", "107 51", ...
6AIZU
p02472 Addition of Big Integers_1472
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 S...
import java.math.BigInteger; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger A = new BigInteger(sc.next()), B = new BigInteger(sc.next()); sc.close(); System.out.println(A.add(B)); } }
4JAVA
{ "input": [ "5 8", "9 8", "17 8", "17 12", "17 16", "21 16", "41 16", "58 16", "58 30", "109 30", "195 30", "302 30", "552 30", "47 30", "87 30", "87 37", "139 37", "139 39", "107 39", "107 73", "107 60", "107 79", "107 51", ...
6AIZU
bico_1473
The much anticipated video game "BiCo Grid" has been released. The rules of "Bico Grid" are very simple. The game field is a 100x100 matrix, where each cell is either a blocked cell, or a cell with some number of coins. For a regular player the look of the field seems pretty random, but the programmer in you recognizes...
C = [[0 for x in xrange(100)] for x in xrange(100)] def dp(): for i in range(100): for j in range(min(99, i)): if j == 0 or j == i: C[i][j] = 1 else: C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; def work(r, c, g): maxUsed = -1 ans = [] x = r ...
1Python2
{ "input": [ "3\n3 2 5\n3 3 10\n5 4 7", "3\n3 2 5\n3 1 10\n5 4 7", "3\n4 2 5\n2 1 10\n5 2 7", "3\n3 2 5\n1 1 7\n5 4 7", "3\n3 2 8\n2 1 10\n5 4 7", "3\n3 2 4\n1 1 7\n5 4 7", "3\n3 2 11\n2 1 10\n5 4 7", "3\n3 2 5\n3 1 4\n5 4 7", "3\n4 2 5\n2 1 10\n5 4 9", "3\n3 2 8\n2 1 10\n5 4 5...
1CODECHEF
cng_1474
In the country of Numberia, there is a city called Primeland. Sherry is one of the rich inhabitants of the city, who likes to collect coins of various denominations. Coins in primeland are little strange , they are only available in prime denominations (i.e as coins of value 2,3,5 etc.).Sherry is taking a tour of the c...
t=int(raw_input()) for i in range (t): c,d=map(int,raw_input().split()) print (c*d-c-d)
1Python2
{ "input": [ "2\n3 5\n2 3", "2\n3 7\n2 3", "2\n3 7\n2 5", "2\n3 7\n0 5", "2\n3 7\n-1 5", "2\n3 7\n-1 7", "2\n2 7\n-1 7", "2\n2 6\n-1 7", "2\n0 6\n-1 7", "2\n0 12\n-1 7", "2\n0 2\n-1 7", "2\n-1 2\n-1 7", "2\n-2 2\n-1 7", "2\n-2 1\n-1 7", "2\n-2 0\n-1 7", ...
1CODECHEF
frgtnlng_1475
Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that is what happened to them. On the happy side of things, a language may be d...
for i in range(input()): NK = map(int, raw_input().split()) strings = map(str, raw_input().split()) phrases = [] for j in range(NK[1]): phrases.append(map(str, raw_input().split())) for j in strings: out = "NO" for k in phrases: if j in k: out = "...
1Python2
{ "input": [ "2\n3 2\npiygu ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz piygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvyj", "2\n3 2\npiygu ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz piygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvzj", "2\n3 2\npiygt ezyfo rzot...
1CODECHEF
lowsum_1476
The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of one satisfaction value and one motivation value for various values of N . The satisfaction and motivation v...
def solve(a,b,num): # temp=[w for w in c] # heapify(temp) # for i in xrange(num): # ans=heappop(temp) # heapify(temp) # return ans while(len(a)*len(b)>num): if len(a)==1 or len(b)==1: break if a[-1]>b[-1]: a.pop() else: b.pop() p=[] for i in xrange(len(a)): for j in xrange(len(b)): p.app...
1Python2
{ "input": [ "1\n3 1\n1 2 3\n4 5 6\n4", "1\n3 1\n1 4 3\n4 5 6\n4", "1\n6 1\n1 4 3\n4 5 6\n1", "1\n6 1\n0 4 3\n4 5 6\n1", "1\n3 1\n1 2 1\n4 5 6\n4", "1\n10 1\n1 4 4\n4 2 12\n1", "1\n10 1\n1 4 4\n4 2 12\n0", "1\n10 1\n1 4 4\n4 2 13\n0", "1\n3 1\n1 4 3\n4 10 6\n4", "1\n6 1\n0 8 6\...
1CODECHEF
prime1_1477
Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers. Input The first line contains t, the number of test cases (less then or equal to 10). Followed by t lines which contain two numbers m and n (1 ≤ m ≤ n ≤ 1000000000, n-...
import sys import math def prime_gen(n1,n2): primes = [] notprimes=[0]*(n2-n1+1) l=int(math.sqrt(n2)) for i in xrange(2,l+1): j=n1//i while j*i<=n2: if j > 1 and j*i >= n1 : notprimes[j*i-n1] = 1 j=j+1 for i in xrange(n1,n2+1): if notpr...
1Python2
{ "input": [ "2\n1 10\n3 5", "2\n1 10\n4 5", "2\n1 10\n7 6", "2\n1 10\n3 7", "2\n1 5\n22 5", "2\n1 10\n1 7", "2\n1 10\n1 6", "2\n1 5\n1 7", "2\n1 6\n1 6", "2\n2 4\n1 9", "2\n4 10\n22 3", "2\n4 5\n22 4", "2\n1 8\n3 5", "2\n1 10\n6 11", "2\n1 4\n1 6", "2\n...
1CODECHEF
tapalin_1478
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your ta...
from sys import stdin from math import ceil MOD=1000000007 inv25=pow(25,MOD-2,MOD) t=int(stdin.readline()) for i in range(0,t): n=int(stdin.readline()) k=(n+1)/2 p26=pow(26,k,MOD) ans = 52 * (p26-1) % MOD * inv25%MOD if n&1: ans = (ans + MOD - p26)%MOD print ans
1Python2
{ "input": [ "5\n1\n2\n3\n4\n100", "5\n1\n3\n3\n4\n100", "5\n1\n2\n3\n4\n110", "5\n1\n2\n1\n4\n110", "5\n1\n4\n1\n4\n110", "5\n1\n2\n3\n4\n101", "5\n1\n3\n3\n4\n110", "5\n1\n2\n3\n4\n111", "5\n1\n2\n2\n4\n110", "5\n1\n4\n1\n4\n100", "5\n1\n2\n3\n5\n100", "5\n2\n3\n3\n4\...
1CODECHEF
1011_A. Stages_1479
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
n, k = map(int, raw_input().split()) st = list(raw_input().strip()) st.sort() cost = 0 count = 0 last = 0 for i in st: if ord(i) >= last + 2 and count < k: last = ord(i) count += 1 cost += ord(i) - ord('a') if count < k: print -1 else: print cost + k
1Python2
{ "input": [ "7 4\nproblem\n", "2 2\nab\n", "5 3\nxyabd\n", "12 1\nabaabbaaabbb\n", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "2 1\nxz\n", "2 2\nac\n", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
2CODEFORCES
1011_A. Stages_1480
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; string s; cin >> s; sort(s.begin(), s.end()); string ans; ans += s[0]; k--; for (int i = 1; i < s.length() && k > 0; i++) { if (k > 0 && s[i] -...
2C++
{ "input": [ "7 4\nproblem\n", "2 2\nab\n", "5 3\nxyabd\n", "12 1\nabaabbaaabbb\n", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "2 1\nxz\n", "2 2\nac\n", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
2CODEFORCES
1011_A. Stages_1481
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
n,k = list(map(int,input().split())) data = sorted(list(input())) data = list(map(lambda x:ord(x)-ord('a')+1,data)) result = 0 used = 0 idx =0 prev = -2 # print(data) for d in data: if d > prev+1: result+= d prev = d used += 1 if used == k: break if used < k: print(-...
3Python3
{ "input": [ "7 4\nproblem\n", "2 2\nab\n", "5 3\nxyabd\n", "12 1\nabaabbaaabbb\n", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "2 1\nxz\n", "2 2\nac\n", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
2CODEFORCES
1011_A. Stages_1482
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
import java.util.*; import java.io.*; public class A { public static void main (String[] args) { Scanner s=new Scanner(System.in); int N=s.nextInt(); int K=s.nextInt(); s.nextLine(); char C1[]=s.nextLine().toCharArray(); Arrays.sort(C1); int L1=C1.length; String S=""+C1[0]; for(int i=1;i<L1;i...
4JAVA
{ "input": [ "7 4\nproblem\n", "2 2\nab\n", "5 3\nxyabd\n", "12 1\nabaabbaaabbb\n", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "2 1\nxz\n", "2 2\nac\n", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
2CODEFORCES
1036_B. Diagonal Walking v.2_1483
Mikhail walks on a Cartesian plane. He starts at the point (0, 0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (1, 1); * (0, 1); * (-1, 1); * (-1, 0); * (-1, -1);...
q = int(raw_input()) def f(n, m, k): if n < m: n, m = m, n if n % 2 != m % 2: n -= 1 k -= 1 elif n % 2 != k % 2: n, m, k = n - 1, m - 1, k - 2 if k < n: return -1 return k for i in range(q): n, m, k = map(int, raw_input().split()) print f(n, m, k)
1Python2
{ "input": [ "3\n2 2 3\n4 3 7\n10 1 9\n", "3\n2 2 3\n4 3 7\n7 1 9\n", "3\n2 2 3\n4 3 9\n7 1 9\n", "3\n2 2 3\n6 1 9\n7 1 1\n", "3\n2 1 3\n6 1 9\n7 0 2\n", "3\n2 0 3\n3 1 9\n13 0 2\n", "3\n4 0 3\n3 1 9\n13 0 2\n", "3\n7 0 0\n3 1 5\n22 0 2\n", "3\n1 0 0\n5 0 5\n22 0 2\n", "3\n1 0 ...
2CODEFORCES
1036_B. Diagonal Walking v.2_1484
Mikhail walks on a Cartesian plane. He starts at the point (0, 0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (1, 1); * (0, 1); * (-1, 1); * (-1, 0); * (-1, -1);...
#include <bits/stdc++.h> using namespace std; int main() { int q; long long int n, m, k, i, bar, left, diag; scanf("%d", &q); while (q--) { scanf("%lld %lld %lld", &n, &m, &k); if (n < m) { i = n; n = m; m = i; } if (n > k) { printf("-1\n"); continue; } else { ...
2C++
{ "input": [ "3\n2 2 3\n4 3 7\n10 1 9\n", "3\n2 2 3\n4 3 7\n7 1 9\n", "3\n2 2 3\n4 3 9\n7 1 9\n", "3\n2 2 3\n6 1 9\n7 1 1\n", "3\n2 1 3\n6 1 9\n7 0 2\n", "3\n2 0 3\n3 1 9\n13 0 2\n", "3\n4 0 3\n3 1 9\n13 0 2\n", "3\n7 0 0\n3 1 5\n22 0 2\n", "3\n1 0 0\n5 0 5\n22 0 2\n", "3\n1 0 ...
2CODEFORCES
1036_B. Diagonal Walking v.2_1485
Mikhail walks on a Cartesian plane. He starts at the point (0, 0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (1, 1); * (0, 1); * (-1, 1); * (-1, 0); * (-1, -1);...
q = int(input()) for i in range(q): n, m, k = map(int, input().split()) if m >k or n > k: print(-1) else: print(k - (k-n)%2 - (k-m)%2)
3Python3
{ "input": [ "3\n2 2 3\n4 3 7\n10 1 9\n", "3\n2 2 3\n4 3 7\n7 1 9\n", "3\n2 2 3\n4 3 9\n7 1 9\n", "3\n2 2 3\n6 1 9\n7 1 1\n", "3\n2 1 3\n6 1 9\n7 0 2\n", "3\n2 0 3\n3 1 9\n13 0 2\n", "3\n4 0 3\n3 1 9\n13 0 2\n", "3\n7 0 0\n3 1 5\n22 0 2\n", "3\n1 0 0\n5 0 5\n22 0 2\n", "3\n1 0 ...
2CODEFORCES
1036_B. Diagonal Walking v.2_1486
Mikhail walks on a Cartesian plane. He starts at the point (0, 0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (1, 1); * (0, 1); * (-1, 1); * (-1, 0); * (-1, -1);...
import java.util.Scanner; public class diagonalWalking { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); long coords[][] = new long[q][2]; long steps[] = new long[q]; for (int i = 0; i < q; i++) { coords[...
4JAVA
{ "input": [ "3\n2 2 3\n4 3 7\n10 1 9\n", "3\n2 2 3\n4 3 7\n7 1 9\n", "3\n2 2 3\n4 3 9\n7 1 9\n", "3\n2 2 3\n6 1 9\n7 1 1\n", "3\n2 1 3\n6 1 9\n7 0 2\n", "3\n2 0 3\n3 1 9\n13 0 2\n", "3\n4 0 3\n3 1 9\n13 0 2\n", "3\n7 0 0\n3 1 5\n22 0 2\n", "3\n1 0 0\n5 0 5\n22 0 2\n", "3\n1 0 ...
2CODEFORCES
1059_A. Cashier_1487
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is...
""" 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": [ "2 11 3\n0 1\n1 1\n", "0 5 2\n", "1 3 2\n1 2\n", "0 1 1\n", "1 5 3\n3 1\n", "0 1000000000 1\n", "3 21 3\n3 3\n9 3\n15 3\n", "0 1000000000 1000000000\n", "1 1 1\n0 1\n", "2 10 3\n0 1\n9 1\n", "1 1000000000 1\n0 1000000000\n", "0 1000000000 500000000\n", ...
2CODEFORCES
1059_A. Cashier_1488
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, L, a; cin >> n >> L >> a; int ans = 0; int prevEnd = 0; for (int i = 0; i < n; i++) { int t, l; cin >> t >> l; ans += (t - prevEnd) / a; prevEnd = t + l; } ans += (...
2C++
{ "input": [ "2 11 3\n0 1\n1 1\n", "0 5 2\n", "1 3 2\n1 2\n", "0 1 1\n", "1 5 3\n3 1\n", "0 1000000000 1\n", "3 21 3\n3 3\n9 3\n15 3\n", "0 1000000000 1000000000\n", "1 1 1\n0 1\n", "2 10 3\n0 1\n9 1\n", "1 1000000000 1\n0 1000000000\n", "0 1000000000 500000000\n", ...
2CODEFORCES
1059_A. Cashier_1489
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is...
n,l,a = map(int,input().split()) b =[] for i in range(n): b.append([int(e) for e in input().split()]) ans = 0 for i in range(n-1): ans += (b[i+1][0] - b[i][1] - b[i][0])//a if(n > 0): ans += b[0][0]//a ans += (l - b[n-1][1] - b[n-1][0])//a else: ans += l//a print(ans)
3Python3
{ "input": [ "2 11 3\n0 1\n1 1\n", "0 5 2\n", "1 3 2\n1 2\n", "0 1 1\n", "1 5 3\n3 1\n", "0 1000000000 1\n", "3 21 3\n3 3\n9 3\n15 3\n", "0 1000000000 1000000000\n", "1 1 1\n0 1\n", "2 10 3\n0 1\n9 1\n", "1 1000000000 1\n0 1000000000\n", "0 1000000000 500000000\n", ...
2CODEFORCES
1059_A. Cashier_1490
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import j...
4JAVA
{ "input": [ "2 11 3\n0 1\n1 1\n", "0 5 2\n", "1 3 2\n1 2\n", "0 1 1\n", "1 5 3\n3 1\n", "0 1000000000 1\n", "3 21 3\n3 3\n9 3\n15 3\n", "0 1000000000 1000000000\n", "1 1 1\n0 1\n", "2 10 3\n0 1\n9 1\n", "1 1000000000 1\n0 1000000000\n", "0 1000000000 500000000\n", ...
2CODEFORCES
1080_C. Masha and two friends_1491
Recently, Masha was presented with a chessboard with a height of n and a width of m. The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is ...
input = raw_input def calc_in_rect(r1, c1, r2, c2): n = r2 - r1 + 1 m = c2 - c1 + 1 if n <= 0 or m <= 0: return [0] * 3 ret = [0, 0, max(0, n * m)] ret[0] = ret[1] = n * m // 2 if (n * m) & 1: ret[(r1 + c1) & 1] += 1 return ret def solve(): n, m = map(int, input().s...
1Python2
{ "input": [ "5\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n", "1\n3456 4567\n1 234 678 1000\n346 903 1005 2003\n", "5\n2 2\n1 1 2 2\n1 1 2 2\n3 5\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\...
2CODEFORCES
1080_C. Masha and two friends_1492
Recently, Masha was presented with a chessboard with a height of n and a width of m. The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is ...
#include <bits/stdc++.h> using namespace std; long long calc(long long x1, long long y1, long long x2, long long y2) { if ((x2 - x1 + 1) * (y2 - y1 + 1) % 2 == 0) return 1; return 2; } int main() { long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long x1, y1, x2, y2; ci...
2C++
{ "input": [ "5\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n", "1\n3456 4567\n1 234 678 1000\n346 903 1005 2003\n", "5\n2 2\n1 1 2 2\n1 1 2 2\n3 5\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\...
2CODEFORCES
1080_C. Masha and two friends_1493
Recently, Masha was presented with a chessboard with a height of n and a width of m. The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is ...
def num_sq(x,y,x2,y2): # b, w a = (abs(x2-x)+1) b = (abs(y2-y)+1) if a % 2 == 0 or b % 2 == 0: return (a*b // 2, a*b // 2) if (x+y) % 2 == 0: num_b = a * b // 2 return (num_b, a * b - num_b) num_w = a * b // 2 return (a * b - num_w, num_w) def pt_in(p1, r1, r2): r...
3Python3
{ "input": [ "5\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n", "1\n3456 4567\n1 234 678 1000\n346 903 1005 2003\n", "5\n2 2\n1 1 2 2\n1 1 2 2\n3 5\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\...
2CODEFORCES
1080_C. Masha and two friends_1494
Recently, Masha was presented with a chessboard with a height of n and a width of m. The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is ...
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.StringTokenizer; /** * Created by timur on 28.03.15. */ public class ...
4JAVA
{ "input": [ "5\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n", "1\n3456 4567\n1 234 678 1000\n346 903 1005 2003\n", "5\n2 2\n1 1 2 2\n1 1 2 2\n3 5\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\...
2CODEFORCES
10_B. Cinema Cashier_1495
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
def updateD(l, k, curI): d = {} for m in xrange(1, k+1): wMin = 1000000 for i in xrange(1, k+2-m): w = 0 ok = True for j in xrange(m): if l[i+j] == 1: ok = False break w += W(curI, k) + W(i+j, k) if ok and w < wMin: wMin = w if wMin != 1000000: d[m] = wMin else: break ...
1Python2
{ "input": [ "4 3\n1 2 3 1\n", "2 1\n1 1\n", "2 3\n3 3\n", "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n", "1 3\n1\n", ...
2CODEFORCES
10_B. Cinema Cashier_1496
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
#include <bits/stdc++.h> using namespace std; int n, k; int a[100][100]; int xc, yc; int lolol(int x, int y) { return abs(x - xc) + abs(y - yc); } int main() { cin >> n >> k; xc = (k + 1) / 2; yc = (k + 1) / 2; for (int asdasd = 0; asdasd < n; asdasd++) { int m; cin >> m; int ans = 999999999; in...
2C++
{ "input": [ "4 3\n1 2 3 1\n", "2 1\n1 1\n", "2 3\n3 3\n", "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n", "1 3\n1\n", ...
2CODEFORCES
10_B. Cinema Cashier_1497
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
__author__ = 'Darren' def solve(): n, k = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k+1)] center = (k + 1) // 2 for m in group: closest, best_row, best_col = 10000, -1, -1 for row in range(1, k+1): col = 0 ...
3Python3
{ "input": [ "4 3\n1 2 3 1\n", "2 1\n1 1\n", "2 3\n3 3\n", "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n", "1 3\n1\n", ...
2CODEFORCES
10_B. Cinema Cashier_1498
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.io.StreamTokenizer; import java.io.Writer; import java.util.Arrays; import ...
4JAVA
{ "input": [ "4 3\n1 2 3 1\n", "2 1\n1 1\n", "2 3\n3 3\n", "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n", "1 3\n1\n", ...
2CODEFORCES
1121_A. Technogoblet of Fire_1499
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
def read_words(func = eval, sp = ' '): return [func(i) for i in raw_input().split(sp)] n, m, k = read_words(int) p = read_words(int) s = read_words(int) c = read_words(int) choose = [(-1, -1)] * m for i in range(n): if choose[s[i]-1][1] < p[i]: choose[s[i]-1] = (i, p[i]) selected = set([i[0] for i...
1Python2
{ "input": [ "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n", "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n", "2 1 1\n1 2\n1 1\n1\n", "2 1 1\n1 2\n1 1\n2\n", "1 1 1\n1\n1\n1\n", "10 5 4\n4 2 1 7 10 9 6 3 5 8\n3 2 1 4 5 1 4 2 4 2\n9 3 2 6\n", "10 1 10\n9 1 2 3 5 7 4 10 6 8\n1 1 1 1 1 1 1 1...
2CODEFORCES