Submission #56698

# Submission time Handle Problem Language Result Execution time Memory
56698 2018-07-12T08:04:29 Z andy0220 None (KOI17_shell) C++11
100 / 100
752 ms 167800 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long lld;
 
int N;
int A[1501][1501], D[1501][1501];
int bit[1501][1502];
int S[1501], E[1501];
 
void add(int n, int v, int bit[1502])
{ for (;n<=N;n+=n&(-n)) bit[n] += v; }
int get(int n, int bit[1502])
{ int ret = 0; for (;n;n^=n&(-n)) ret += bit[n]; return ret; }
 
inline int dp(int i, int j){ return D[i][j] + get(j, bit[i]); }
 
int main()
{
    scanf("%d", &N);
    for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) scanf("%d", A[i]+j);
    lld ans = 0;
    for (int i=1;i<=N;i++) for (int j=1;j<=N;j++){
        D[i][j] = max(D[i-1][j], D[i][j-1]) + A[i][j];
        ans += D[i][j];
    }
    printf("%lld\n", ans);
    for (int t=1;t<=N;t++){
        char c; int y, x; scanf(" %c%d%d", &c, &y, &x);
        int v = c == 'U' ? 1 : -1;
        for (int i=y;i<=N;i++) S[i] = N+1, E[i] = 0;
        S[y] = E[y] = x;
        for (int ny=y,nx=x;;){
            if (nx < N && max(dp(ny-1, nx+1), dp(ny, nx))+v == max(dp(ny-1, nx+1), dp(ny, nx)+v)) nx++;
            else ny++;
            if (ny > N) break;
            E[ny] = nx;
        }
        for (int ny=y,nx=x;;){
            if (ny < N && max(dp(ny+1, nx-1), dp(ny, nx))+v == max(dp(ny+1, nx-1), dp(ny, nx)+v)) ny++;
            else nx++;
            if (nx > N || E[ny] < nx) break;
            S[ny] = min(S[ny], nx);
        }
        for (int i=y;i<=N;i++) if (S[i] <= E[i]){
            add(S[i], v, bit[i]);
            add(E[i]+1, -v, bit[i]);
            ans += v * (E[i]-S[i]+1);
        }
        printf("%lld\n", ans);
    }
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
shell.cpp:21:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) scanf("%d", A[i]+j);
                                                   ~~~~~^~~~~~~~~~~~~~
shell.cpp:29:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         char c; int y, x; scanf(" %c%d%d", &c, &y, &x);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1656 KB Output is correct
2 Correct 7 ms 1804 KB Output is correct
3 Correct 6 ms 1968 KB Output is correct
4 Correct 6 ms 2128 KB Output is correct
5 Correct 6 ms 2128 KB Output is correct
6 Correct 6 ms 2128 KB Output is correct
7 Correct 5 ms 2204 KB Output is correct
8 Correct 4 ms 2208 KB Output is correct
9 Correct 7 ms 2232 KB Output is correct
10 Correct 6 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 25536 KB Output is correct
2 Correct 295 ms 29704 KB Output is correct
3 Correct 333 ms 40744 KB Output is correct
4 Correct 330 ms 40744 KB Output is correct
5 Correct 286 ms 42052 KB Output is correct
6 Correct 367 ms 47528 KB Output is correct
7 Correct 306 ms 51868 KB Output is correct
8 Correct 329 ms 55236 KB Output is correct
9 Correct 354 ms 59636 KB Output is correct
10 Correct 405 ms 64472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1656 KB Output is correct
2 Correct 7 ms 1804 KB Output is correct
3 Correct 6 ms 1968 KB Output is correct
4 Correct 6 ms 2128 KB Output is correct
5 Correct 6 ms 2128 KB Output is correct
6 Correct 6 ms 2128 KB Output is correct
7 Correct 5 ms 2204 KB Output is correct
8 Correct 4 ms 2208 KB Output is correct
9 Correct 7 ms 2232 KB Output is correct
10 Correct 288 ms 25536 KB Output is correct
11 Correct 295 ms 29704 KB Output is correct
12 Correct 333 ms 40744 KB Output is correct
13 Correct 330 ms 40744 KB Output is correct
14 Correct 286 ms 42052 KB Output is correct
15 Correct 367 ms 47528 KB Output is correct
16 Correct 306 ms 51868 KB Output is correct
17 Correct 329 ms 55236 KB Output is correct
18 Correct 354 ms 59636 KB Output is correct
19 Correct 405 ms 64472 KB Output is correct
20 Correct 472 ms 80348 KB Output is correct
21 Correct 470 ms 89028 KB Output is correct
22 Correct 461 ms 97700 KB Output is correct
23 Correct 607 ms 106224 KB Output is correct
24 Correct 702 ms 114760 KB Output is correct
25 Correct 689 ms 123480 KB Output is correct
26 Correct 315 ms 123480 KB Output is correct
27 Correct 285 ms 132196 KB Output is correct
28 Correct 454 ms 140792 KB Output is correct
29 Correct 498 ms 149400 KB Output is correct
30 Correct 681 ms 157920 KB Output is correct
31 Correct 752 ms 166580 KB Output is correct
32 Correct 313 ms 166580 KB Output is correct
33 Correct 320 ms 167800 KB Output is correct
34 Correct 6 ms 2256 KB Output is correct