제출 #1281917

#제출 시각아이디문제언어결과실행 시간메모리
1281917KerimColouring a rectangle (eJOI19_colouring)C++20
0 / 100
65 ms125780 KiB
#include "bits/stdc++.h"

using namespace std;
const int N = 4004;
int d, n, m;
int a[N], b[N];
vector<pair<pair<int,int>,int > > intervals;
long long cost[N];
long long dp[N][N];
long long rec(int pos, int rp){
    if (pos == intervals.size())
        return 0;
    long long &ret=dp[pos][rp];
    if (~ret)
        return ret;
    int a_value = intervals[pos].second;
    int l = intervals[pos].first.first;
    int r = intervals[pos].first.second;
    ret = rec(pos+1, rp) + a_value;
    ret = min(ret, rec(pos+1, max(rp, r)) + cost[max(rp, r)] - cost[rp]);
    return ret;
} 


// 0: a[i]
// 1: interval used [l, r]
// dp[i][0/1]

// dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + a[i]
// dp[i][1] = min(dp[i-1][0]+ sumB(l[i], r[i]),
//              dp[j][1] + sumB(r[j], r[i]) + 
//              sumA(j+1, i-1)) 

// - r[j] <= r[i]
//  dp[j][1] + sumB[r[i]]-sumB[r[j]] + sumA[i-1] - sumA[j]
// - else
//  dp[j][1] + sumA[i-1] - sumA[j]

// - r[j] <= r[i]
//  dp[i][1] = min(find(1, r[i]) + sumB[r[i]] + sumA[i-1])//find i
//  upd(r[i], dp[i][1] - sumB[r[i]] - sumA[i]) //update, j

// - else
//  dp[i][1] = min(find(r[i]+1, N) + sumA[i-1])//find i
//  upd(r[i], dp[i][1] - sumA[i]) //update, j


long long solve(){
    // for (int i = 0; i < intervals.size(); i++){
    //     cout<<intervals[i].first.first<<" "<<intervals[i].first.second<<endl;
    // }
    sort(intervals.begin(), intervals.end());
    for (int i = 1; i <= d; i++)
        cost[i] += cost[i-1];
    memset(dp, -1, sizeof dp);
    return rec(0, 0);
}
int f(int x, int y){
    return x + y - 1;
}
int main(){
    // freopen("file.in", "r", stdin);
    scanf("%d%d", &n, &m);
    d = n+m-1;
    for (int i = 1; i <= d; i++)
        scanf("%d", a+i);
    reverse(a+1, a+d+1);
    for (int i = 1; i <= d; i++)
        scanf("%d", b+i);
    for (int i = 1; i <= d; i+=2){
        int x, y, xp, yp;
        if (i <= n)
            x = n-i+1, y = 1;
        else
            x = 1, y = i-n+1;
        int k = min(n-x, m-y);
        xp = x+k; yp = y+k;
        intervals.push_back({{f(x, y), f(xp, yp)}, a[i]});
    }

    for(int i = 1; i <= d; i++){
        if (i%2 == n%2)
            cost[i] = b[i];
        else
            cost[i] = 0;
    }
    long long answer = solve();

    intervals.clear(); 
    for (int i = 2; i <= d; i+=2){
        int x, y, xp, yp;
        if (i <= n)
            x = n-i+1, y = 1;
        else
            x = 1, y = i-n+1;
        int k = min(n-x, m-y);
        xp = x+k; yp = y+k;
        intervals.push_back({{f(x, y), f(xp, yp)}, a[i]});
    }

    for(int i = 1; i <= d; i++){
        if (i%2 != n%2)
            cost[i] = b[i];
        else
            cost[i] = 0;
    }
    answer += solve();



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


컴파일 시 표준 에러 (stderr) 메시지

colouring.cpp: In function 'int main()':
colouring.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
colouring.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d", a+i);
      |         ~~~~~^~~~~~~~~~~
colouring.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d", b+i);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...