Dataset Viewer
Auto-converted to Parquet Duplicate
contest_id
stringclasses
33 values
problem_id
stringclasses
14 values
statement
stringclasses
181 values
tags
sequencelengths
1
8
code
stringlengths
21
64.5k
language
stringclasses
3 values
1301
D
D. Time to Runtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going...
[ "constructive algorithms", "graphs", "implementation" ]
import os import sys from io import BytesIO, IOBase from collections import Counter BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode ...
py
1305
D
D. Kuroni and the Celebrationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem; Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortun...
[ "constructive algorithms", "dfs and similar", "interactive", "trees" ]
import os, sys from io import BytesIO, IOBase from math import log2, ceil, sqrt, gcd from _collections import deque import heapq as hp from bisect import bisect_left, bisect_right from math import cos, sin from itertools import permutations # sys.setrecursionlimit(2*10**5+10000) BUFSIZE = 8192 class Fas...
py
1285
D
D. Dr. Evil Underscorestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; as a friendship gift, Bakry gave Badawy nn integers a1,a2,…,ana1,a2,…,an and challenged him to choose an integer XX such that the value max1≤i≤n(ai⊕X)max1≤i≤n(ai⊕X) is minimum possible, whe...
[ "bitmasks", "brute force", "dfs and similar", "divide and conquer", "dp", "greedy", "strings", "trees" ]
import sys input=lambda:sys.stdin.readline().rstrip() def calc(A,i,j,k): if k==0: return 0 if A[i]%(k*2)>=k or A[j]%(k*2)<k: return calc(A,i,j,k//2) index=i+[l%(k*2)>=k for l in A[i:j+1]].index(1) return k+min(calc(A,i,index-1,k//2),calc(A,index,j,k//2)) def solve(): n=int(input()) A=sorted(list(ma...
py
1325
B
B. CopyCopyCopyCopyCopytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEhab has an array aa of length nn. He has just enough free time to make a new array consisting of nn copies of the old array, written back-to-back. What will be the length of the new array's longe...
[ "greedy", "implementation" ]
t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) c=set(arr) print(len(c))
py
1285
D
D. Dr. Evil Underscorestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; as a friendship gift, Bakry gave Badawy nn integers a1,a2,…,ana1,a2,…,an and challenged him to choose an integer XX such that the value max1≤i≤n(ai⊕X)max1≤i≤n(ai⊕X) is minimum possible, whe...
[ "bitmasks", "brute force", "dfs and similar", "divide and conquer", "dp", "greedy", "strings", "trees" ]
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def binary_trie(): G0, G1, cnt = [-1], [-1], [0] return G0, G1, cnt def insert(x, l): j = 0 for i in range(l, -1, -1): cnt[j] += 1 if x & pow2[i]: if G1[j] == -1: G0...
py
1303
E
E. Erase Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss. You can build new string pp from ss using the following operation no more than two times: choose any subsequence si1,si2,…,siksi1,si2,…,sik where 1≤i1<i2<⋯<ik≤|s|1≤i1<i...
[ "dp", "strings" ]
T = int(input()) for ti in range(T): s, t = input().strip(), input().strip() N = len(t) for i in range(1, N+1): dp = [0]+[-1]*i for l, c in enumerate(s): for j in range(i, -1, -1): tmp = dp[j] if dp[j] != -1 and i + dp[j] < N and \ ...
py
1324
E
E. Sleeping Scheduletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova had a pretty weird sleeping schedule. There are hh hours in a day. Vova will sleep exactly nn times. The ii-th time he will sleep exactly after aiai hours from the time he woke up. You can assu...
[ "dp", "implementation" ]
import os import sys from io import BytesIO, IOBase MOD0 = 10 ** 9 + 7 MOD1 = 998244353 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file....
py
1141
F2
F2. Same Sum Blocks (Hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two editions; which differ exclusively in the constraints on the number nn.You are given an array of integers a[1],a[2],…,a[n].a[1],a[2],…,a[n]. A block is a sequence ...
[ "data structures", "greedy" ]
from collections import defaultdict n = int(input()) arr = list(map(int, input().split())) pre = [0]*(n+1) for i in range(n): pre[i+1] = pre[i] + arr[i] mp = defaultdict(list) for i in range(n): for j in range(i,n): sum = pre[j+1] - pre[i] mp[sum].append((i,j)) k = 0 ans ...
py
1316
D
D. Nash Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. This board game is played on the n×nn×n b...
[ "constructive algorithms", "dfs and similar", "graphs", "implementation" ]
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List """ created by shhuan at 2020/3/13 21:15 """ def check(x, y, N): return 1 <= x <= N and 1 <= y <= N def dfs(x, y, d, marks, X, ...
py
1303
E
E. Erase Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss. You can build new string pp from ss using the following operation no more than two times: choose any subsequence si1,si2,…,siksi1,si2,…,sik where 1≤i1<i2<⋯<ik≤|s|1≤i1<i...
[ "dp", "strings" ]
import sys input = sys.stdin.readline test = int(input()) for _ in range(test): s = input().rstrip() t = input().rstrip() n = len(s) m = len(t) ansls = [] pos = [[1000 for i in range(26)] for j in range(n+2)] for i in range(n+1)[::-1]: if i < n: for j in range(26): pos[i][j]...
py
1141
D
D. Colored Bootstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn left boots and nn right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings ll and rr, both of length nn. The...
[ "greedy", "implementation" ]
from collections import defaultdict as dc n=int(input()) a,b=list(input()),list(input()) frqa=dc(lambda:list()) frqb=dc(lambda:list()) for i in range(n):frqa[a[i]].append(i) for i in range(n):frqb[b[i]].append(i) i=96 ans=list() #print(ord('?'))=63 while i<=122: i+=1 c=chr(i) if c in frqa and c...
py
1285
A
A. Mezo Playing Zomatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands: 'L' (Left) sets the position...
[ "math" ]
l = int(input()) input() print(l + 1)
py
1305
E
E. Kuroni and the Score Distributiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done; and he is discussing with the team about the score distrib...
[ "constructive algorithms", "greedy", "implementation", "math" ]
import random, sys, os, math, gc from collections import Counter, defaultdict, deque from functools import lru_cache, reduce, cmp_to_key from itertools import accumulate, combinations, permutations, product from heapq import nsmallest, nlargest, heapify, heappop, heappush from io import BytesIO, IOBase from copy ...
py
1322
B
B. Presenttime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCatherine received an array of integers as a gift for March 8. Eventually she grew bored with it; and she started calculated various useless characteristics for it. She succeeded to do it for each one she cam...
[ "binary search", "bitmasks", "constructive algorithms", "data structures", "math", "sortings" ]
import sys input = sys.stdin.buffer.readline def radix(a): digits = len(str(max(a))) for i in range (digits): b = [[] for _ in range (10)] e = pow(10, i) for j in a: num = (j//e)%10 b[num].append(j) a *= 0 for l in b: ...
py
1305
D
D. Kuroni and the Celebrationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem; Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortun...
[ "constructive algorithms", "dfs and similar", "interactive", "trees" ]
import sys import math import heapq import bisect from collections import Counter from collections import defaultdict from io import BytesIO, IOBase import string class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno...
py
1299
A
A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for an...
[ "brute force", "greedy", "math" ]
# 13:17- import sys input = lambda: sys.stdin.readline().rstrip() N = int(input()) A = list(map(int, input().split())) cnt = [0]*32 for i in range(32): for a in A: if a&(1<<i): cnt[i]+=1 find = -1 for i in range(31,-1,-1): if cnt[i]==1: find = i break if find>=0: idx = 0 for i in r...
py
1295
D
D. Same GCDstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers aa and mm. Calculate the number of integers xx such that 0≤x<m0≤x<m and gcd(a,m)=gcd(a+x,m)gcd(a,m)=gcd(a+x,m).Note: gcd(a,b)gcd(a,b) is the greatest common divisor of aa and bb.I...
[ "math", "number theory" ]
import sys import math from math import * import builtins input = sys.stdin.readline def print(x, end='\n'): sys.stdout.write(str(x) + end) # IO helpers def get_int(): return int(input()) def get_list_ints(): return list(map(int, input().split())) def get_char_list(): s = ...
py
1287
A
A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a walking tour day in SIS.Winter; so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are an...
[ "greedy", "implementation" ]
for _ in range(int(input())): n = int(input()) m, t = 0, 0 a = input() if n == 1 or len(set(a)) == 1: print(0) continue j = a.index('A') for i in range(j + 1, n): if a[i] == 'P': t += 1 else: m = max(m, t) t = 0 ...
py
1323
A
A. Even Subset Sum Problemtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array aa consisting of nn positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 22) or determine that there is no such subse...
[ "brute force", "dp", "greedy", "implementation" ]
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) for i in range(n): if arr[i] % 2 == 0: print(1) print(i + 1) break else: if n == 1: print(-1) else: print(2) p...
py
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
from sys import stdin input = stdin.readline import math for case in range(int(input())): n, m = map(int, input().split()) ans = n * (n + 1) // 2 small = (n - m)//(m + 1); avg_split = (n - m)/(m + 1) large = small + 1 num_large = (n - m) % (m + 1) num_small = m + 1 - num_large ...
py
1312
C
C. Adding Powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are performing the following algorithm. There is an array v1,v2,…,vnv1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at ii-th step (00-...
[ "bitmasks", "greedy", "implementation", "math", "number theory", "ternary search" ]
R=lambda:map(int,input().split()) t,=R() for _ in[0]*t: n,k=R();a=*R(),;r='YES' while any(a): if[x%k for x in a if x%k]>[1]:r='NO' a=[x//k for x in a] print(r)
py
1284
D
D. New Year and Conferencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFilled with optimism; Hyunuk will host a conference about how great this new year will be!The conference will have nn lectures. Hyunuk has two candidate venues aa and bb. For each of the nn l...
[ "binary search", "data structures", "hashing", "sortings" ]
import sys input = lambda: sys.stdin.readline().rstrip() N=100101 n = int(input()) rand = [((i+12345)**3)%998244353 for i in range(N*2+20)] al,ar,bl,br=[],[],[],[] for _ in range(n): a,b,c,d=map(int,input().split()) al.append(a) ar.append(b) bl.append(c) br.append(d) def calk(l,r): ma={s:idx f...
py
1288
B
B. Yet Another Meme Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers AA and BB, calculate the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b)...
[ "math" ]
for _ in [0]*int(input()): a,b = map(int, input().split()) print(a*(len(str(b+1))-1))
py
1304
D
D. Shortest and Longest LIStime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong recently learned how to find the longest increasing subsequence (LIS) in O(nlogn)O(nlog⁡n) time for a sequence of length nn. He wants to test himself if he can implement it correctly,...
[ "constructive algorithms", "graphs", "greedy", "two pointers" ]
def main(): t=int(input()) allans=[] for _ in range(t): n,s=input().split() n=int(n) s=s+'$' seq=[] # [isIncreasing,length] prev=None l=0 for c in s: if c!=prev: if l>0: # not first ...
py
1325
D
D. Ehab the Xorcisttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven 2 integers uu and vv, find the shortest array such that bitwise-xor of its elements is uu, and the sum of its elements is vv.InputThe only line contains 2 integers uu and vv (0≤u,v≤1018)(0≤u,v≤1...
[ "bitmasks", "constructive algorithms", "greedy", "number theory" ]
import sys from math import * from collections import * inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write # n=int(inp()) # arr=list(map(int,inp().split())) def solve(): u,v=map(int,inp().split()) if v%2!=u%2 or u>v: print(-1) return if u==v==0: ...
py
1284
D
D. New Year and Conferencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFilled with optimism; Hyunuk will host a conference about how great this new year will be!The conference will have nn lectures. Hyunuk has two candidate venues aa and bb. For each of the nn l...
[ "binary search", "data structures", "hashing", "sortings" ]
from operator import itemgetter import sys import bisect input = sys.stdin.readline class BIT(): """区間加算、区間取得クエリをそれぞれO(logN)で答える add: 区間[l, r)にvalを加える get_sum: 区間[l, r)の和を求める l, rは0-indexed """ def __init__(self, n): self.n = n self.bit0 = [0] * (n + 1) s...
py
1295
A
A. Display The Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a large electronic screen which can display up to 998244353998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit...
[ "greedy" ]
t = int(input()) for _ in range(t): segments = int(input()) if segments < 2: print("1") else: rem = segments % 2 if rem: total_ones = segments - 3 total = "7"+("1"*(total_ones//2)) print(total) else: ones = "1"*(...
py
1290
A
A. Mind Controltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou and your n−1n−1 friends have found an array of integers a1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: All nn of you stand in a line in a particular order. Each minute, the p...
[ "brute force", "data structures", "implementation" ]
#z=int(input()) import math alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26} alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g",...
py
1325
C
C. Ehab and Path-etic MEXstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of nn nodes. You want to write some labels on the tree's edges such that the following conditions hold: Every label is an integer between 00 and n−2n−2 inclusiv...
[ "constructive algorithms", "dfs and similar", "greedy", "trees" ]
import sys input = sys.stdin.readline n = int(input()) d = [[] for i in range(n)] w = [] for i in range(n-1): a, b = map(lambda x:int(x)-1, input().split()) d[a].append((b, i)) d[b].append((a, i)) q = [] for i in d: if len(i) >= 3: q = i break if q == []: for i i...
py
1288
B
B. Yet Another Meme Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers AA and BB, calculate the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b)...
[ "math" ]
n = int(input()) output = [ ] for i in range(n): A, B = [int(x) for x in input().split()] output.append(A * (len(str(B+1)) - 1)) print(*output, sep = "\n")
py
1290
A
A. Mind Controltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou and your n−1n−1 friends have found an array of integers a1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: All nn of you stand in a line in a particular order. Each minute, the p...
[ "brute force", "data structures", "implementation" ]
import sys input=sys.stdin.readline a = [0 for i in range(3505)] q = int(input()) for _ in range(q): n, m, k = map(int, input().split()) a[1:] = list(map(int, input().split())) k = min(k, m-1) re, ans = n-k, 0 for l in range(1, n-re+2): r, x, len = l + re - 1, int(1e9), n-m+1 ...
py
1288
C
C. Two Arraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that: the length of both arrays is equal to mm; each element of each array is an integer between 11 and nn (in...
[ "combinatorics", "dp" ]
mod=int(1e9+7) def read(): return [int(i) for i in input().split()] """ dp[i][j]: dp[i+x][j-x] next[i][j]: dp[i][j]+dp[i-1][j]+dp[i][j-1]+dp[i-1][j-1] increasing in a, decreasing in b ndp[i][j]: dp[i][j] + dp[i][j+1] + dp[i-1][j] """ def main(): n,m=read() # a: increasing, b: decreasing ...
py
1304
A
A. Two Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing tired of participating in too many Codeforces rounds; Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller ...
[ "math" ]
for i in [*open(0)][1:]: x,y,a,b=map(int,i.split()) a+=b y-=x print([y//a,-1][y%a>0])
py
1320
B
B. Navigation Systemtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe map of Bertown can be represented as a set of nn intersections, numbered from 11 to nn and connected by mm one-way roads. It is possible to move along the roads from any intersection to any othe...
[ "dfs and similar", "graphs", "shortest paths" ]
import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(3001) input = sys.stdin.readline ng= collections.defaultdict(list) sp = coll...
py
1287
A
A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a walking tour day in SIS.Winter; so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are an...
[ "greedy", "implementation" ]
t = int(input()) while t > 0: t -= 1 n = int(input()) s = input() ang, mx, cnt = 0, 0, 0 for i in range(n): if s[i] == 'A': ang = 1 mx = max(mx, cnt) cnt = 0 elif ang and s[i] == 'P': cnt += 1 mx = max(mx, cnt) print(mx) ...
py
1287
A
A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a walking tour day in SIS.Winter; so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are an...
[ "greedy", "implementation" ]
t = int(input()) for _ in range(t): k = int(input()) s = input() ans = 0 while "AP" in s: s = s.replace("AP", "AA") ans += 1 print(ans)
py
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py import os import sys from io import BytesIO, IOBase import math from heapq import heappop, heappush, heapify, heapreplace from collections import defaultdict, deque, OrderedDict from bisect import bisect_left, bisect_righ...
py
13
E
E. Holestime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:There are N holes located in a single row and numbered from left to right with numbers from 1 to N. ...
[ "data structures", "dsu" ]
import sys input = sys.stdin.readline n, m = map(int, input().split()) p = list(map(int, input().split())) BLOCK_LENGTH = 350 block = [i//BLOCK_LENGTH for i in range(n)] jumps = [0] * n end = [0] * n for i in range(n - 1, -1, -1): nex = i + p[i] if nex >= n: jumps[i] = 1 end[...
py
1325
D
D. Ehab the Xorcisttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven 2 integers uu and vv, find the shortest array such that bitwise-xor of its elements is uu, and the sum of its elements is vv.InputThe only line contains 2 integers uu and vv (0≤u,v≤1018)(0≤u,v≤1...
[ "bitmasks", "constructive algorithms", "greedy", "number theory" ]
from sys import stdin input = stdin.readline u, v = [int(x) for x in input().split()] if u > v or (v-u)%2 == 1: print(-1) elif u == v == 0: print(0) elif u == v: print(1); print(u) else: x = (v-u)//2 # if ((u+x)^x) == u and u+x+x == v: print(2); print(u+x, x) if (u&x) == 0: print(2); print(u+x,...
py
1288
B
B. Yet Another Meme Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers AA and BB, calculate the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b)...
[ "math" ]
t=int(input()) for i in range(t): a,b=map(int,input().split()) print(a*(len(str(b+1))-1))
py
1290
B
B. Irreducible Anagramstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call two strings ss and tt anagrams of each other if it is possible to rearrange symbols in the string ss to get a string, equal to tt.Let's consider two strings ss and tt which are anagram...
[ "binary search", "constructive algorithms", "data structures", "strings", "two pointers" ]
def charToInt(c): #'a'->0 return ord(c)-ord('a') def main(): s=input() n=len(s) arr=[charToInt(c) for c in s] p=makeArr(0,n,26) for i in range(n): p[i][arr[i]]+=1 for i in range(1,n): for j in range(26): p[i][j]+=p[i-1][j] def g...
py
13
C
C. Sequencetime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes to play very much. And most of all he likes to play the following game:He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. ...
[ "dp", "sortings" ]
import bisect import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os, sys import profile import cProfile import random import re import string from bisect import bisect_left, bisect_right from collections import de...
py
1321
A
A. Contest for Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, a...
[ "greedy" ]
i=lambda:input().split() i();a,b=i(),i();c=d=0 for i,x in enumerate(a):c+=x>b[i];d+=b[i]>x print([[1--(d+1-c)//max(1,c),1][c>d],-1][c<1])
py
1304
D
D. Shortest and Longest LIStime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong recently learned how to find the longest increasing subsequence (LIS) in O(nlogn)O(nlog⁡n) time for a sequence of length nn. He wants to test himself if he can implement it correctly,...
[ "constructive algorithms", "graphs", "greedy", "two pointers" ]
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): t = int(input()) for _ in range(t): n, s = input().split() n = int(n) hi, prev = n, 0 mi = [0] * n for i in range(n): if i == n - 1 or s[i] == '>': for j ...
py
1296
E2
E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a...
[ "data structures", "dp" ]
from collections import defaultdict, Counter,deque from math import sqrt, log10, log, floor, factorial,gcd from bisect import bisect_left, bisect_right from itertools import permutations,combinations import sys, io, os input = sys.stdin.readline # input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # sys.s...
py
1290
B
B. Irreducible Anagramstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call two strings ss and tt anagrams of each other if it is possible to rearrange symbols in the string ss to get a string, equal to tt.Let's consider two strings ss and tt which are anagram...
[ "binary search", "constructive algorithms", "data structures", "strings", "two pointers" ]
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def main(): s=input().rstrip() n=len(s) dp=[[0 for _ in range(26)] for _ in range(n+1)] for i,v in enumerate(s): dp[i+1][ord(v)-97]=1 for j in range(26): ...
py
1284
A
A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Ko...
[ "implementation", "strings" ]
import math n, m = [int(x) for x in input().split()] s, t = input().split(), input().split() lowermn = min(n, m) ip = int(input()) for _ in range(ip): year = int(input()) - 1 print(s[year%n] + t[year%m])
py
1324
C
C. Frog Jumpstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a frog staying to the left of the string s=s1s2…sns=s1s2…sn consisting of nn characters (to be more precise, the frog initially stays at the cell 00). Each character of ss is either 'L' or 'R'. It...
[ "binary search", "data structures", "dfs and similar", "greedy", "implementation" ]
for i in range(int(input())): l = input().split("R") l.sort() print(len(l[-1])+1)
py
1322
C
C. Instant Noodlestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWu got hungry after an intense training session; and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.You are given...
[ "graphs", "hashing", "math", "number theory" ]
import sys input = sys.stdin.buffer.readline def gcd(a, b): if a > b: a, b = b, a if b % a==0: return a return gcd(b % a, a) t = int(input()) for i in range(t): n, m = [int(x) for x in input().split()] C = [int(x) for x in input().split()] G = [] for...
py
End of preview. Expand in Data Studio

This is a dataset collected and created from Codeforces rounds.

All the problem statements, solutions and problem_tags are from Codeforces's API requests. https://codeforces.com/apiHelp

The dataset is in the following format

{
  "contest_id": "1290",
  "problem_id": "A",
  "statement": "A. Mind Controltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou and your n−1n−1 friends have found an array of integers a1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: All nn of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.You are standing in the mm-th position in the line. Before the process starts, you may choose up to kk different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.Suppose that you're doing your choices optimally. What is the greatest integer xx such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to xx?Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.InputThe input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases. The description of the test cases follows.The first line of each test case contains three space-separated integers nn, mm and kk (1≤m≤n≤35001≤m≤n≤3500, 0≤k≤n−10≤k≤n−1)  — the number of elements in the array, your position in line and the number of people whose choices you can fix.The second line of each test case contains nn positive integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109)  — elements of the array.It is guaranteed that the sum of nn over all test cases does not exceed 35003500.OutputFor each test case, print the largest integer xx such that you can guarantee to obtain at least xx.ExampleInputCopy4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\nOutputCopy8\n4\n1\n1\nNoteIn the first test case; an optimal strategy is to force the first person to take the last element and the second person to take the first element.  the first person will take the last element (55) because he or she was forced by you to take the last element. After this turn the remaining array will be [2,9,2,3,8][2,9,2,3,8];  the second person will take the first element (22) because he or she was forced by you to take the first element. After this turn the remaining array will be [9,2,3,8][9,2,3,8];  if the third person will choose to take the first element (99), at your turn the remaining array will be [2,3,8][2,3,8] and you will take 88 (the last element);  if the third person will choose to take the last element (88), at your turn the remaining array will be [9,2,3][9,2,3] and you will take 99 (the first element). Thus, this strategy guarantees to end up with at least 88. We can prove that there is no strategy that guarantees to end up with at least 99. Hence, the answer is 88.In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 44.",
  "tags": [
          "brute force",
          "data structures",
          "implementation"
        ],
  "code": "#Don't stalk me, don't stop me, from making submissions at high speed. If you don't trust me,\n\nimport sys\n\n#then trust me, don't waste your time not trusting me. I don't plagiarise, don't fantasize,\n\nimport os\n\n#just let my hard work synthesize my rating. Don't be sad, just try again, everyone fails\n\nfrom io import BytesIO, IOBase\n\nBUFSIZE = 8192\n\n#every now and then. Just keep coding, just keep working and you'll keep progressing at speed-\n\n# -forcing.\n\nclass FastIO(IOBase):\n\n    newlines = 0\n\n    def __init__(self, file):\n\n        self._fd = file.fileno()\n\n        self.buffer = BytesIO()\n\n        self.writable = \"x\" in file.mode or \"r\" not in file.mode\n\n        self.write = self.buffer.write if self.writable else None\n\n    def read(self):\n\n        while True:\n\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\n            if not b:\n\n                break\n\n            ptr = self.buffer.tell()\n\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n\n        self.newlines = 0\n\n        return self.buffer.read()\n\n    def readline(self):\n\n        while self.newlines == 0:\n\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\n            self.newlines = b.count(b\"\\n\") + (not b)\n\n            ptr = self.buffer.tell()\n\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n\n        self.newlines -= 1\n\n        return self.buffer.readline()\n\n    def flush(self):\n\n        if self.writable:\n\n            os.write(self._fd, self.buffer.getvalue())\n\n            self.buffer.truncate(0), self.buffer.seek(0)\n\nclass IOWrapper(IOBase):\n\n    def __init__(self, file):\n\n        self.buffer = FastIO(file)\n\n        self.flush = self.buffer.flush\n\n        self.writable = self.buffer.writable\n\n        self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n\n        self.read = lambda: self.buffer.read().decode(\"ascii\")\n\n        self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n\n#code by _Frust(CF)/Frust(AtCoder)\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\n\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\nfrom os import path\n\nif(path.exists('input.txt')):\n\n    sys.stdin = open(\"input.txt\",\"r\")\n\n    sys.stdout = open(\"output.txt\",\"w\")\n\n    input = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\n\n\ninf=float(\"inf\")\n\n\n\nfor _ in range(int(input())):\n\n    # n=int(input())\n\n    n, m, k=map(int, input().split())\n\n    l1=[int(i) for i in input().split()]\n\n    ans=-inf\n\n    if k<m:\n\n        #0, 1, 2, ... k\n\n        for i in range(k+1): \n\n            temp=inf\n\n            #0, 1, 2, ... m-k-1 in total deleting m-1 elements\n\n            for j in range(m-k): \n\n                left=i+j\n\n                right=m-1-left\n\n                lele=l1[left]\n\n                rele=l1[n-right-1]\n\n                # print(left, right, lele, rele)\n\n                temp=min(max(l1[left], l1[n-(right+1)]), temp)\n\n\n\n            ans=max(ans, temp)\n\n        \n\n    else:\n\n        for i in range(m):\n\n            temp=inf\n\n            left=i\n\n            right=m-1-left\n\n            lele=l1[left]\n\n            rele=l1[n-right-1]\n\n            # print(left, right, lele, rele)\n\n            temp=min(max(l1[left], l1[n-(right+1)]), temp)\n\n            ans=max(ans, temp)\n\n    print(ans)\n\n\n\n    ",
  "language": "py"
},

There are three language in the dataset: python, c++, java, which is "py", "cpp", "java"

For further finetuing the unixcoder algorithm classification model and further inference sample, please refer to the github repo: https://github.com/AlbertQiSun/LLM-enhanced-competitive-coding-algorithm-retrieval?tab=readme-ov-file

Downloads last month
24