Submission #144037

#TimeUsernameProblemLanguageResultExecution timeMemory
144037OrtAutomobil (COCI17_automobil)Pypy 2
0 / 100
39 ms11488 KiB
def gauss(fr,to,nums): return ((fr+to)*nums)//2 def val(y,x): return (y-1)*m + x n, m, k = map(int,input().split()); Mr = dict(); Mc = dict(); for i in range(k): c, x, y = map(str, input().split()) x = int(x); y = int(y); if(c=='R'): try: Mr[x]*=y except KeyError: Mr[x]=y if(c=='S'): try: Mc[x]*=y except KeyError: Mc[x]=y upd_r = list(Mr.items()) upd_c = list(Mc.items()) upd_r.sort(); upd_c.sort(); sol = 0; sum_w = 0; for col, col_up in upd_c: last_row = 1; for row, row_up in upd_r: if(row==last_row): c = val(row,col); sol = sol + (c*row_up*col_up); sum_w = sum_w + c; last_row = row+1; continue; elif(row==last_row+1): c = val(last_row,col); sol = sol + (c*col_up); sum_w = sum_w+c; last_row = row+1; else: cl = val(last_row, col); ch = val(row-1, col); sum_range = gauss(cl,ch,row-last_row); mult_range = sum_range * col_up; sol = sol + mult_range; sum_w = sum_w + sum_range; last_row = row+1; c = val(row,col); sol = sol + (c*col_up*row_up); sum_w = sum_w + c; last_row = row + 1; if(last_row>n): continue; elif(last_row==n): c = val(n, col); sol = sol + (c*col_up); sum_w = sum_w+c; else: cl = val(last_row, col); ch = val(n, col); sum_range = gauss(cl,ch,n-last_row+1); mult_range = sum_range*col_up sol = sol+mult_range sum_w = sum_w+sum_range for row, row_up in upd_r: last_col = 1; for col, col_up in upd_c: if(last_col==col): last_col = col+1; continue; elif(col==last_col+1): c = val(row, last_col); sol = sol + (c*row_up); sum_w = sum_w + c; last_col = col+1; continue; else: cl = val(row, last_col) ch = val(row,col-1) sum_range = gauss(cl,ch,col-last_col) mult_range = sum_range * row_up sol = sol + mult_range; sum_w = sum_w + sum_range last_col = col+1; if(last_col>m): continue; elif(last_col==m): c = val(row, m); sol = sol + (c*row_up); sum_w = sum_w+c; else: cl = val(row,last_col); ch = val(row,m); sum_range = gauss(cl,ch,m-last_col+1); mult_range = sum_range * row_up; sol = sol + mult_range; sum_w = sum_w + sum_range; t = n * m; total_no_update = (t*(t+1))//2 res = total_no_update - sum_w; sol = sol+res; print(sol%1000000007)
#Verdict Execution timeMemoryGrader output
Fetching results...