답안 #217594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217594 2020-03-30T10:26:52 Z DodgeBallMan 비밀 (JOI14_secret) C++14
0 / 100
504 ms 4732 KB
#include <bits/stdc++.h>
#include "secret.h"

const int N = 1e3 + 10;

int n, a[N], prer[10][N], prel[10][N];

//int Secret( int a, int b ) { return a + b; }

void solve( int l = 1, int r = n, int cnt = 1 ) {
    if( cnt > 8 || l == r ) return ;
    int mid = l + r >> 1;
    prer[cnt][mid+1] = a[mid+1];
    prel[cnt][mid] = a[mid];
    //printf("CNT %d L %d R %d\n",cnt,l,r);
    //printf("%d ",prel[cnt][mid]);
    for( int i = mid - 1 ; i >= l ; i-- ) {
        prel[cnt][i] = Secret( prel[cnt][i+1], a[i] );
        //printf("%d ",prel[cnt][i]);
    }
    //printf("\n");
    //printf("%d ",prer[cnt][mid+1]);
    for( int i = mid + 2 ; i <= r ; i++ ) {
        prer[cnt][i] = Secret( prer[cnt][i-1], a[i] );
        //printf("%d ",prer[cnt][i]);
    }
    //printf("\n");
    solve( l, mid, cnt+1 ), solve( mid+1, r, cnt+1 );
}


void Init( int N, int A[] ) {
    n = N;
    for( int i = 1 ; i <= n ; i++ ) a[i] = A[i-1];
    solve();
}

int cal( int ll, int rr, int l = 1, int r = n, int cnt = 1 ) {
    if( rr == ll ) return a[ll];
    if( rr == ll + 1 ) return Secret( a[ll], a[rr] );
    int mid = l + r >> 1;
    if( ll <= mid && mid <= rr ) return Secret( prel[cnt][ll], prer[cnt][rr] );
    else if( rr <= mid ) return cal( ll, rr, l, mid );
    else return cal( ll, rr, mid + 1, r );
}

int Query( int L, int R ) { return cal( L+1, R+1 ); }

/*int main()
{
    int n, x[N], q;
    scanf("%d",&n);
    for( int i = 0 ; i < n ; i++ ) scanf("%d",&x[i]);
    Init( n, x );
    for( int i = 1 ; i <= 8 ; i++ ) {
        for( int j = 1 ; j <= n ; j++ ) printf("%d ",prel[i][j]);

    }
    scanf("%d",&q);
    while( q-- ) {
        int a, b;
        scanf("%d %d",&a,&b);
        printf("%d\n",Query( a, b ) );
    }
}*/

Compilation message

secret.cpp: In function 'void solve(int, int, int)':
secret.cpp:12:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
secret.cpp: In function 'int cal(int, int, int, int, int)':
secret.cpp:41:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 2552 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 55847107.
2 Incorrect 138 ms 2608 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 311474560.
3 Incorrect 138 ms 2552 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 353554500.
4 Incorrect 499 ms 4600 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 536936657.
5 Incorrect 499 ms 4472 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 212882718.
6 Incorrect 501 ms 4576 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 423176097.
7 Incorrect 499 ms 4472 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 675449873.
8 Incorrect 504 ms 4600 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 273091792.
9 Incorrect 500 ms 4732 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 827853577.
10 Incorrect 499 ms 4472 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 337854787.