Submission #144037

# Submission time Handle Problem Language Result Execution time Memory
144037 2019-08-15T18:24:48 Z Ort Automobil (COCI17_automobil) PyPy
0 / 100
39 ms 11488 KB
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 time Memory Grader output
1 Runtime error 35 ms 11488 KB Execution failed because the return code was nonzero
2 Runtime error 33 ms 11300 KB Execution failed because the return code was nonzero
3 Runtime error 32 ms 11228 KB Execution failed because the return code was nonzero
4 Runtime error 33 ms 11332 KB Execution failed because the return code was nonzero
5 Runtime error 33 ms 11360 KB Execution failed because the return code was nonzero
6 Runtime error 33 ms 11352 KB Execution failed because the return code was nonzero
7 Runtime error 32 ms 11356 KB Execution failed because the return code was nonzero
8 Runtime error 39 ms 11220 KB Execution failed because the return code was nonzero
9 Runtime error 34 ms 11356 KB Execution failed because the return code was nonzero
10 Runtime error 33 ms 11224 KB Execution failed because the return code was nonzero
11 Runtime error 34 ms 11348 KB Execution failed because the return code was nonzero
12 Runtime error 34 ms 11360 KB Execution failed because the return code was nonzero
13 Runtime error 35 ms 11352 KB Execution failed because the return code was nonzero
14 Runtime error 34 ms 11332 KB Execution failed because the return code was nonzero
15 Runtime error 32 ms 11224 KB Execution failed because the return code was nonzero
16 Runtime error 33 ms 11340 KB Execution failed because the return code was nonzero
17 Runtime error 33 ms 11236 KB Execution failed because the return code was nonzero
18 Runtime error 36 ms 11224 KB Execution failed because the return code was nonzero
19 Runtime error 33 ms 11232 KB Execution failed because the return code was nonzero
20 Runtime error 33 ms 11232 KB Execution failed because the return code was nonzero