답안 #929185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
929185 2024-02-17T22:16:16 Z Stavab Colouring a rectangle (eJOI19_colouring) C++14
0 / 100
8 ms 3676 KB
#include <iostream>

using namespace std;

#define INF 9999999999999999

int A[200005][2];
int B[200005][2];
long long prSum[200005][2];

int main()
{
    freopen("coloring.in", "r", stdin);
    freopen("coloring.out", "w", stdout);


    int N, M;
    scanf("%d %d", &N, &M);

    int input;
    for(int i = 0; i < 2; i++)
    {
        for(int j = 1; j <= N + M - 1; j++)
        {
            scanf("%d", &input);

            if(i == 0)
            {
                if(j % 2 == 1)
                    A[(j + 1) / 2][0] = input;
                else
                    A[j / 2][1] = input;
            }
            else
            {
                if(j % 2 == 1)
                    B[(j + 1) / 2][0] = input;
                else
                    B[j / 2][1] = input;
            }
        }
    }

    for(int i = 0; i < 2; i++)
        for(int j = 1; j <= N; j++)
            prSum[j][i] = prSum[j - 1][i] + B[j][i];


    long long answer = 0;

    if(N % 2 == 1)
    {
        long long tmpAnswer = INF;
        long long sum = 0;

        int size = (N + 1) / 2;
        for(int j = 0; j < size; j++)
        {
            tmpAnswer = min(tmpAnswer, sum + prSum[N - j][0] - prSum[j][0]);

            if(j == 0)
                sum += A[size][0];
            else
            {
                sum += A[size + j][0];
                sum += A[size - j][0];
            }
        }
        tmpAnswer = min(tmpAnswer, sum);
        answer += tmpAnswer;

        tmpAnswer = INF;
        sum = 0;
        size = (N - 1) / 2;
        for(int j = 0; j < size; j++)
        {
            tmpAnswer = min(tmpAnswer, sum + prSum[N - 1 - j][1] - prSum[j][1]);

            sum += A[size - j][1];
            sum += A[size + 1 + j][1];
        }
        tmpAnswer = min(tmpAnswer, sum);
        answer += tmpAnswer;
    }
    else
    {
        long long tmpAnswer = INF;
        long long sum = 0;

        int size = N / 2;
        for(int j = 0; j < size; j++)
        {
            tmpAnswer = min(tmpAnswer, sum + prSum[N - j][0] - prSum[j][0]);

            if(j == 0)
                sum += A[size][1];
            else
            {
                sum += A[size + j][1];
                sum += A[size - j][1];
            }
        }
        tmpAnswer = min(tmpAnswer, sum);
        answer += tmpAnswer;

        tmpAnswer = INF;
        sum = 0;
        size = N / 2;
        for(int j = 0; j < size; j++)
        {
            tmpAnswer = min(tmpAnswer, sum + prSum[N - 1 - j][1] - prSum[j][1]);

            sum += A[size - j][0];
            sum += A[size + 1 + j][0];
        }
        tmpAnswer = min(tmpAnswer, sum);
        answer += tmpAnswer;
    }

    printf("%lld\n", answer);

    return 0;
}

Compilation message

colouring.cpp: In function 'int main()':
colouring.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("coloring.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
colouring.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("coloring.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
colouring.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
colouring.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |             scanf("%d", &input);
      |             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 3624 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -