Problem:


Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003



Sample input:
2 3
1 32
2 63
1 12


Sample output:
000001000002
000002000001
000001000001

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

def numberlize(n):
    k="000000"
    u=6-len(str(n))
    return k[0:u]+str(n)
#print(numberize(5))
    
    
n,m=MI()
lis=[[]for i in range(n)]
for i in range(m):
    a,b=MI()
    lis[a-1].append([i+1,b])
#print(lis)
for j in range(n):
    lis[j]=sorted(lis[j],key=lambda x:x[1])
    for k in range(len(lis[j])):
        lis[j][k][1]=k+1
#print(lis)

ans=[0 for i in range(m)]
for j in range(n):
    for s in lis[j]:
        ans[s[0]-1]=[j+1,s[1]]
#print(ans)
for a in ans:
    print(numberlize(a[0])+numberlize(a[1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,M=pin()#NofKen,MofSi
    PY=[[]for i in range(N)]
    
    for m in range(M):
        p,y=pin()
        PY[p-1].append([y,m])
    #print(PY)
    ANS=[]
    for i in range(N):
        PY[i].sort(key=lambda x:x[0])
        for n,py in enumerate(PY[i]):
            py[0]=n+1
            ANS.append([i+1]+py)
    #print(ANS)
    ANS.sort(key=lambda x:x[2])
    
    
    #print(ANS)
    PY=ANS
    for k in range(M):
        x,y,z=PY[k]
        X,Y=str(x),str(y)
        t,s=6-len(X),6-len(Y)
        if t>0:
            X="0"*t+X
        if s>0:
            Y="0"*s+Y
        print(X+Y)

#%%submit!
resolve()

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
q = []
for i in range(m):
    p , y = map(int,input().split())
    q.append([p,y,i])
ans = [0 for i in range(m)]
q.sort()

now = q[0][0]
cou = 1
for a , b , c in q:
    if now != a:
        now = a
        cou = 1
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
        cou += 1
    elif now == a:
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
        cou += 1
        
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import bisect
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    d = [[] for _ in range(N + 1)]
    PY = []
    for _ in range(M):
        p, y = map(int, input().split())
        d[p].append(y)
        PY.append((p, y))

    for i in range(N + 1):
        if not d[i]:
            continue
        d[i] = sorted(set(d[i]))

    for p, y in PY:
        order = bisect.bisect_left(d[p], y)
        print(str(p).zfill(6) + str(order + 1).zfill(6))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = []
p_y = [[] for i in range(n)]
for _ in range(m):
    p,y = map(int,input().split())
    py.append((p,y))
    p_y[p-1].append(y)
ans = {}
for i, tmp in enumerate(p_y):
    cnt = 1
    p_y[i] = tmp.sort()
    for j, jj in enumerate(tmp):
 
        ans[(i+1, jj)] = str(i+1).zfill(6) + str(j+1).zfill(6)
 
 
for i, tmp in enumerate(py):
    print(ans[tmp])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

citys = []
for i in range(m):
    p, y = map(int, input().split())
    citys.append([p, y, i])
    
citys.sort(key=lambda x: x[1])
citys.sort()

ans = [[str("{:06}".format(citys[0][0])) + str("{:06}".format(1)), citys[0][2]]]
num = 2
for i in range(1, m):
    if citys[i - 1][0] != citys[i][0]:
        num = 1
    
    ans.append([str("{:06}".format(citys[i][0])) + str("{:06}".format(num)), citys[i][2]])
    
    num += 1

ans.sort(key=lambda x: x[1])
for i in range(m):
    print(ans[i][0])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    num = i+1
    p,y = map(int,input().split())
    py.append([num,p,y])
py = sorted(py, key = lambda x:x[1]*10**10+x[2])
x = 0
b = '000000'
ans = []
for pyi in py:
    if pyi[1] != x:
        x = pyi[1]
        cnt = 1
    else:
        cnt += 1
    ans.append([pyi[0], (b+str(pyi[1]))[-6:], (b+str(cnt))[-6:]])
ans = sorted(ans, key = lambda x: x[0])
for ansi in ans:
    print(ansi[1]+ansi[2])

Submission status: Accepted

Solution code:
import bisect
inf = 10**15
mod = 10**9+7
n, m = map(int, input().split())
ken = [[] for i in range(n)]
py = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    p, y = py[i]
    ken[p-1].append(y)
for tmp in ken:
    tmp.sort()
for i in range(m):
    p, y = py[i]
    ind = bisect.bisect_left(ken[p-1], y)
    print('{ans:06}{anse:06}'.format(ans=p, anse=ind+1))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
city = [[] for _ in range(N + 1)]
for i in range(M):
    p, y = map(int, input().split())
    city[p].append([y, i + 1])
ans = [-1 for _ in range(M + 1)]
for k in range(1, N + 1):
    tmp = city[k]
    if len(tmp) > 0:
        for j, t in enumerate(sorted(tmp)):
            name = str(k).zfill(6) + str(j + 1).zfill(6)
            ans[t[1]] = name
print("\n".join(ans[1:]))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[[0]*3 for i in range(m)]
for i in range(m):
    py[i]=list(map(int,input().split()))+[i]

py.sort()

strr=[""]*m
pyi=0
for i in range(m):
    if py[i][0]==pyi:
        strp=str(py[i][0])
        strq="0"*(6-len(strp))+strp        
        qi+=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    else:
        strp=str(py[i][0])
        pyi=py[i][0]
        strq="0"*(6-len(strp))+strp        
        qi=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    strr[py[i][2]]=strq

for i in range(m):
    print(strr[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)]
PY = sorted(PY, key=lambda x:(x[0], x[1]))
k=1
PY[0][1]=k
for i in range(1,M):
  if PY[i][0]!=PY[i-1][0]:
    k=1
  else:
    k+=1
  PY[i][1]=k
PY = sorted(PY, key=lambda x:x[2])
for p,y,_ in PY:
  print('{0:06}{1:06}'.format(p,y))

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

n, m = list(map(int, input().split(' ')))

pym = [None] * m
for i in range(m):
    pym[i] = [i] + list(map(int, input().split(' ')))

pyms = sorted(pym, key=itemgetter(1, 2))

x = 1
pyms[0].append(x)

for i in range(1, m):
    if pyms[i - 1][1] != pyms[i][1]:
        x = 1
    else:
        x += 1
    pyms[i].append(x)
    
pym = sorted(pyms, key=itemgetter(0, ))

for i in range(m):
    city_id = str(pym[i][1]).zfill(6) + str(pym[i][3]).zfill(6)
    print(city_id)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(M):
    P,Y=map(int,input().split())
    A.append([P,Y,i])
A.sort()
a=str(A[0][0])
n="0"*(6-len(a))+a+"0"*5+"1"
A[0].append(n)
no=1
for i in range(1,M):
    if A[i][0]==A[i-1][0]:
        no=no+1
    else:
        no=1
    a=str(A[i][0])
    b=str(no)
    n="0"*(6-len(a))+a+"0"*(6-len(b))+b
    A[i].append(n)
A.sort(key=lambda x:x[2])
for i in range(M):
    print(A[i][3])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y,i))
    A.sort()
    cunt,pre,ans=0,0,[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append((a[2],s1.zfill(6)+s2.zfill(6)))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s[1])

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    dct = {}
    for i in range(m):
        p, y = MI()
        dct.setdefault(p, [])
        dct[p].append((i, y))
    # print(dct)

    ans = ['' for _ in range(m)]
    for key, value in dct.items():
        st = sorted(value, key=lambda x: x[1])
        # print(st)
        for idx, (i, year) in enumerate(st):
            id = str(key).zfill(6) + str(idx+1).zfill(6)
            # print(id)
            ans[i] = id

    for iid in ans:
        print(iid)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    dct = {}
    for i in range(m):
        p, y = MI()
        dct.setdefault(p, [])
        dct[p].append((i, y))
    # print(dct)

    ans = ['' for _ in range(m)]
    for key, value in dct.items():
        st = sorted(value, key=lambda x: x[1])
        # print(st)
        for idx, (i, year) in enumerate(st):
            id = str(key).zfill(6) + str(idx+1).zfill(6)
            # print(id)
            ans[i] = id

    for iid in ans:
        print(iid)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import collections
import bisect
n,m = map(int,input().split())
p = [[int(j) for j in input().split()] for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x] += [y]
for x,y in p:
  z = bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[list(map(int,(str(_+1)+' '+input()).split())) for _ in range(m)]
py.sort(key=lambda x:x[1]*10**10+x[2])
pi=0
x=0
b='000000'
ans=[]
for pyi in py:# pyi=[i,pi,yi]
  if pyi[1]!=pi:
    x=1
    pi=pyi[1]
  else:
    x+=1
  ans.append([pyi[0],(b+str(pyi[1]))[-6:]+(b+str(x))[-6:]])
ans.sort(key=lambda x:x[0])
for ansi in ans:# ansi=[i,識別番号]
  print(ansi[1])

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    PY = [il() for _ in range(M)]
    k = {}
    sortPY = sorted(PY, key=lambda x: (x[0], x[1]))

    tmp = 0
    cnt = 1
    for p, y in sortPY:
        if p != tmp:
            cnt = 1
            tmp = p
        else:
            cnt += 1

        k[y] = cnt

    for p, y in PY:
        print(str(p).zfill(6) + str(k[y]).zfill(6))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# AtCoder
from collections import defaultdict
import bisect
N, M = map(int, input().split())

cities = defaultdict(list)
p = [[int(j) for j in input().split()] for i in range(M)]

for x, y in sorted(p):
    cities[x].append(y)

for x, y in p:
    z = bisect.bisect(cities[x], y)
    print("%06d%06d" % (x, z))

Submission status: Accepted

Solution code:
from bisect import bisect_right
n,m=map(int,input().split())
k=[[] for i in range(n+1)]
p,y=[0]*m,[0]*m
for i in range(m):
    p[i],y[i]=map(int,input().split())
    k[p[i]].append(y[i])
for i in range(n+1):
    k[i].sort()
for i in range(m):
    x=bisect_right(k[p[i]],y[i])
    ans1=str(p[i])
    while len(ans1)<6:
        ans1="0"+ans1
    ans2=str(x)
    while len(ans2)<6:
        ans2="0"+ans2
    print(ans1+ans2)

Submission status: Accepted

Solution code:
def main(): 
  n,m=map(int,input().split())
  py=[list(map(int,input().split()))+[i+1] for i in range(m)]
  py.sort(key=lambda x:(x[0],x[1],x[2]))
  py[0].append(1)
  cnt=1
  for i in range(1,m):
    cnt=cnt+1 if py[i][0]==py[i-1][0] else 1
    py[i].append(cnt)
  py.sort(key=lambda x:x[-2])
  for a,b,c,d in py:
    print(str(a).zfill(6)+str(d).zfill(6))
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc113/tasks/abc113_c

n, m = map(int, input().split())

ans = [0] * m
cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append((i, p, y))
prefec = [[] for _ in range(n)]
cities.sort(key=lambda x: x[2]) # 年でsort

for i, p, y in cities:
    prefec[p - 1].append((i))

for i in range(len(prefec)):
    pre = prefec[i]
    for j in range(len(pre)):
        index = pre[j]
        head = '000000' + str(i + 1)
        head = head[-6:]
        tail = '000000' + str(j + 1)
        tail = tail[-6:]
        ans[index] = head + tail

for r in ans:
    print(r)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

pylst = []
py = [[] for _ in range(N+1)]

for i in range(M):
    p, y = map(int, input().split())
    pylst.append([y, p, i])

sorted_pylst = sorted(pylst)

for y, p, i in sorted_pylst:
    py[p].append([y, i])

ans = [0]*M

for i, lst in enumerate(py):
    cnt = 1
    for j, k in lst:
        ans[k] = '{0:06d}{1:06d}'.format(i, cnt)
        cnt += 1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n , m = map(int, input().split())
id =[]
ch = 1
for i in range(m):
    p , y = map(int, input().split())
    id.append([p,y,i])
id.sort(key = lambda x:(x[0],x[1]))
id.append(['X','X','X'])
for i in range(m):
    id[i][1]=str(ch).zfill(6)
    if id[i][0]==id[i+1][0]:
        ch+=1
    else:
        ch=1
id.pop()
id.sort(key = lambda x:x[2])
for i in range(m):
    s = str(id[i][0]).zfill(6)+id[i][1]
    print(s)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]

for i in range(m):
    py[i].append(i+1)

py.sort()

#print(py)
now=py[0][0]
co=0

for j in range(m):
    t=py[j][0]
    if t==now:
        co+=1
        py[j][1]=co
    else:
        now=py[j][0]
        co=1
        py[j][1]=co

#print(py)

py.sort(key=lambda x:x[2])
#print(py)

for a,b,c in py:
    print(str(a).rjust(6,'0')+str(b).rjust(6,'0'))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

N, M = [int(x) for x in input().split()]
city = []

for n in range(M):
    P, Y = [int(x) for x in input().split()]
    city.append([n, P, Y])
city = np.array(city)
city = city[np.argsort(city[:, 2])]
counts = np.array([1]*N)

city2 = []

for n in range(M):
    city2.append([city[n, 0], city[n, 1], city[n, 2], counts[city[n, 1]-1]])
    counts[city[n, 1]-1] += 1

city2 = np.array(city2)
city2 = city2[np.argsort(city2[:, 0])]
for c in city2:
    print(str(c[1]).zfill(6) + str(c[3]).zfill(6))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
P=[0]*M
Y=[0]*M
T=[0]*M
for i in range(M):  
  P[i],Y[i] = map(int,input().split())
  T[i] = [i,P[i],Y[i]]

T.sort(key=lambda x:(x[1],x[2]))
for i,item in enumerate(T):
  if i==0:
    item.append(1)
  else:
    if T[i][1]==T[i-1][1]:
      item.append(T[i-1][3]+1)
    else:
      item.append(1)
      
T.sort(key=lambda x:(x[0],x[3]))

for item in T:
  city = str(item[1])
  city = (6-len(city))*"0"+city
  order =  str(item[3])
  order = (6-len(order))*"0"+order
  print(city+order)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
cur = [1] * (N+1)  # 1-indexed
PY = [lr() + [i] for i in range(M)]
PY.sort(key=lambda x: x[1])
answer = [None] * M  # 0-indexed
for p, y, i in PY:
    x = str(p).zfill(6) + str(cur[p]).zfill(6)
    answer[i] = x
    cur[p] += 1

for a in answer:
    print(a)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
py = []
mli = [0]*n
li = [""]*m

for i in range(m):
    p,y = map(int, input().split())
    py.append([p,y,i])

py.sort(key=lambda x: x[1])

for p,y,i in py:
    mli[p-1] += 1
    pi = str(p).zfill(6)
    yi = str(mli[p-1]).zfill(6)
    li[i] = pi+yi

for i in li:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
from bisect import bisect_left

n, m = map(int, input().split())
years = defaultdict(list)
sorted_years = defaultdict(list)
PY = []
for i in range(m):
    prefecture, year = map(int, input().split())
    years[prefecture].append(year)
    PY.append((prefecture, year))

for prefecture, year_list in years.items():
    temp = year_list
    temp.sort()
    sorted_years[prefecture] = temp

for pair in PY:
    p, y = pair
    years[p]
    num = 1 + bisect_left(sorted_years[p], y)
    print(str(p).zfill(6) + str(num).zfill(6))

Submission status: Accepted

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    prefectures = [[]*M for _ in range(N)]
    for i in range(M):
        p, y = LMIIS()
        prefectures[p-1].append((y,i))
    dbg(prefectures)
    for p in prefectures:
        p.sort()
    dbg(prefectures)
    cities = [0]*M
    for i,p in enumerate(prefectures):
        for j,(y,k) in enumerate(p):
            cities[k] = '{:06d}{:06d}'.format(i+1,j+1)
    for s in cities:
        print(s)

        
        


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
'''
N  個の県があり、これらの県には合計で 
M 個の市が属しています。
市i が誕生したのは Yi 年であり、県 Pi に属しています。
それぞれの市に12 桁の認識番号を割り振ることとなりました。
市 i が 県 Pi に属する市の中で x 番目に誕生した市のとき、
市i の認識番号の上 6 桁は Pi、下 6 桁は x となります。

出力するのは県の番号とその県の中で何番目に誕生したかを
組み合わせたものになります。
したがって、まずは市を県ごとに分ける必要があります。
また、最終的にはもともとinputで受け取った順番で出力する
必要があるので、市ごとに配列に分けてそれぞれの配列に
誕生した年と初めのinputで受け取った順番を組にしたものをいれます。
このもとでそれぞれの県ごとの配列
'''
n,m=map(int,input().split())
pyi=[[] for i in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    pyi[p-1].append([y,i])#県の下に、市をぶら下げる（出来た年とi）
ans=[]
for i in range(n):#県ごとに処理
    #print(pyi[i])
    pyi[i].sort()#県内で出来た年でソート
    #print(pyi[i])
    for j in range(len(pyi[i])):
        ans.append([(6-len(str(i+1)))*"0"+str(i+1)+\
                    (6-len(str(j+1)))*"0"+str(j+1),pyi[i][j][1]])
        #pyi[i][j][1]は初めのinputで受け取った順番
#print(ans)
ans.sort(key=lambda x:x[1])#入力順に並び変える
#print(ans)
for i in range(m):
    print(ans[i][0])#0は識別番号

Submission status: Accepted

Solution code:
inputs = open(0).readlines()
n, m = map(int, inputs[0].split())
PY = [map(int, x.split()) for x in inputs[1:]]
A = [[] for _ in range(n)]
B = [''] * m
for i, (p, y) in enumerate(PY):
    A[p-1].append([y, i])
    B[i] += '{:06}'.format(p)
for a in A:
    a.sort()
    for i in range(len(a)):
        B[a[i][1]] += '{:06}'.format(i+1)
print(*B, sep='\n')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
D = [[] for i in range(N)]
 
for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) 

ans = [None]*M
 
for i, d in enumerate(D): 
  d.sort()
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6)
print(*ans, sep = '\n')

Submission status: Accepted

Solution code:
from bisect import bisect_right
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append((p,y))
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]
#print(all_li)
#[[1, 32], [2, 63], [1, 12]]
#print(ma)
# {1: [32, 12], 2: [63]}
sorted_li = [[] for _ in range(n)]
for k,v in ma.items():
    sorted_li[k-1] = list(sorted(v))
#print(ma)
for a in all_li:
    #print(a[1],sorted_li[a[0]-1])
    count = bisect_right(sorted_li[a[0]-1],a[1],)
    #count = sorted_li[a[0]-1].index(a[1]) + 1
    print(str(a[0]).zfill(6)+str(count).zfill(6))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

P = [0]*m
Y = [0]*m

city = [[] for _ in range(n)]

for i in range(m):
  P[i],Y[i] = map(int,input().split())
  city[P[i] - 1].append((Y[i],i))

for i in range(n):
  for j,(y,c) in enumerate(sorted(city[i])):
    Y[c] = j + 1

for p,y in zip(P,Y):
  print('{:0>6}'.format(p) + '{:0>6}'.format(y))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py = []
d = {}
for i in range(M):
    p, y = map(int, input().split())
    py.append([p, y])
    if p not in d:
        d[p] = [y]
    else:
        d[p].append(y)
for key in d.keys():
    d[key].sort()
from bisect import bisect_left
for i in range(M):
    p, y = py[i]
    a = bisect_left(d[p], y)
    ans = '0' * (6 - len(str(p))) + str(p)
    ans += '0' * (6 - len(str(a + 1))) + str(a + 1)
    print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = []
for k, v in city_list_grouped:
  ans += [[v[2],format(k,'0>6')+format(i+1,'0>6')] for i,v in enumerate(v)]

for x in sorted(ans):
  print(x[1])

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

for x in sorted(ans):
  print(x[1])

Submission status: Accepted

Solution code:

N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
count = [0]*(N+1)
ans = [0]*(M+1)
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

data.sort(key=lambda x: x[1])

for i in range(M):
    count[data[i][0]] += 1
    ans[data[i][2]] = count[data[i][0]]


for j in range(1,M+1):
    a = P[j-1]
    b = ans[j]
    print(str(a*(10**6)+b).zfill(12))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    N, M =  [int(i) for i in input().split()]
    cities = []

    for i in range(M):
        p, y = map(int, input().split())
        cities.append([p, y, i])

    cities.sort()
    ans = []

    num = 0
    before = cities[0][0]

    for i in range(M):
        if before != cities[i][0]:
            num = 1
            before = cities[i][0]
        else:
            num += 1
        ans.append([cities[i][0], num, cities[i][2]])

    ans.sort(key=lambda x:x[2])
    for a in ans:
        s = str(a[0]).zfill(6) + str(a[1]).zfill(6)
        print(s)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    answer = ["" for _ in range(m)]
    all_pref = {}
    for i in range(m):
        p, y = map(int, input().split())
        if p in all_pref:
            all_pref[p].append([y, i])
        else:
            all_pref[p] = [[y, i]]
    for pref, date in all_pref.items():
        date.sort(key=lambda x: x[0])
        order = 0
        for year, num in date:
            answer[num] = str(pref).zfill(6) + str(order + 1).zfill(6)
            order += 1
    print("\n".join(answer))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
py = [[] for _ in range(n)]
for i in range(m):
    p,y = map(int, input().split())
    data = (y, i) # year, origIndx
    py[p-1].append(data)

    
xx = [[] for _ in range(m)]
for ken in range(0, n):
    py[ken].sort(key=lambda x: x[0])
    for i in range(len(py[ken])):
        x = py[ken][i]
        xx[x[1]] = "%s%s" % (str(ken+1).zfill(6), str(i+1).zfill(6))
print("\n".join(xx), end="")

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) + [i] for i in range(M)]

PY.sort()

ans = [None for i in range(M)]

x = 1
P = PY[0][0]
for i in range(M):
    if P != PY[i][0]:
        x = 1
        P = PY[i][0]

    ans[PY[i][2]] = (P,x)
    x += 1

for p,x in ans:
    print(str(p).zfill(6) + str(x).zfill(6))

Submission status: Accepted

Solution code:
def pad(n):
	n = str(n)
	if len(n) < 6:
		n = "0"*(6-len(n))+n
	return n

N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]

for i in range(M):
	PY[i].append(i)
PY.sort()

turn = 1
PY[0].append(pad(PY[0][0])+pad(turn))
for i in range(1,M):
	if PY[i][0] != PY[i-1][0]:
		turn = 1
	else:
		turn += 1
	PY[i].append(pad(PY[i][0])+pad(turn))

PY.sort(key = lambda x:x[2])
for i in range(M):
	print(PY[i][3])

Submission status: Accepted

Solution code:
# solution

nim,mike=map(int,input().split())

array=[]

for i in range(mike):
    p,y=map(int,input().split())
    array.append([i,p,y])

PY_sort=sorted(array,key=lambda x: x[2])

k=list(range(1,10**5+1))

v=[0]*10**5

cnt_dict=dict(zip(k,v))

arr=[]

for i,j,k in PY_sort:
    cnt_dict[j]+=1
    arr.append([i,str(j).zfill(6)+str(cnt_dict[j]).zfill(6)])

s = sorted(arr, key=lambda x: x[0])

for a,b in s:
    print(b)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    from collections import defaultdict
    import bisect
    p = [list(map(int,input().split())) for _ in range(m)]
    a = defaultdict(list)
    for x,y in sorted(p):
        a[x] += [y]
    for x,y in p:
        z = bisect.bisect_right(a[x],y)
        print("%06d%06d"%(x,z))
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:


def solve():
    N, M = map(int, input().split())

    # N分の二次元配列を用意する
    piys = [[] for _ in range(N)]
    # 各県を添え字として市を格納していく
    for i in range(M):
        p, y = map(int, input().split())
        piys[p-1].append((y, i))

    ans = [None]*M
    # enumrateで添字付きで県、市の配列を見る
    # p = index, iys = 市となる
    for p, iys in enumerate(piys):
        iys.sort()
        # enumrateで添字付きで市の配列を見る
        # k = 誕生順, y = 経過時間、i = 元のpiysの順序となる
        for k, (y, i) in enumerate(iys):
            pref = str(p+1)
            born = str(k+1)
            # 左を０埋めする
            ans[i] = pref.rjust(6, "0")+born.rjust(6, "0")

    for i in ans:
        print(i)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]
l=[1]*n
for i in range(m):
    py[i].append(i+1)
py.sort()
for i in range(m):
    py[i].append( str(py[i][0]).zfill(6) + str(l[py[i][0]-1]).zfill(6))
    l[py[i][0]-1]+=1
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][-1])

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, sys.stdin.readline().rstrip().split())
    PY = []
    for i in range(M):
        P, Y = map(int, sys.stdin.readline().rstrip().split())
        PY.append([Y, P, i + 1])
    PY.sort()

    # cnt: key=県, value=すでに幾つの市がその県に属しているか
    # res: [市の番号, 県の番号, 順番]
    cnt = {}
    res = []
    for y, p, i in PY:
        if p not in cnt:
            cnt[p] = 1
        else:
            cnt[p] += 1
        res.append([i, p, cnt[p]])

    res.sort()
    for i, p, x in res:
        print('{:06}{:06}'.format(p, x))