이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
struct edge {
    int j, x; ll w;
    edge(){}
    edge(int j, ll w, int x):j(j),w(w),x(x){}
};
int n, m, p;
int arr[50][50];
ll dis[2100000];
ll INF = (1LL<<60);
vector<edge> lis[2100000];
int val(int x, int y) {return x*(m+1)+y;}
int rval(int val, int xo) {return val*(1<<p)+xo;}
void dijk() {
    int i, j;
    for (i=0;i<(n+1)*(m+1);i++) {
        for (j=0;j<(1<<p);j++) dis[rval(i,j)] = INF;
    }
    dis[rval(val(0,0),0)] = 0;
    priority_queue<pli> pq;
    pq.push(pli(0,rval(val(0,0),0)));
    while(!pq.empty()) {
        pli tmp = pq.top();
        pq.pop();
        int here = tmp.second;
        ll w = -tmp.first;
        for (i=0;i<lis[here].size();i++) {
            int there = lis[here][i].j;
            int ww = lis[here][i].w;
            if (dis[there]>dis[here]+ww) {
                dis[there]=dis[here]+ww;
                pq.push(pli(-dis[there],there));
            }
        }
    }
    printf("%lld\n",dis[rval(val(0,0),(1<<p)-1)]);
}
int main() {
    int i, j, k;
    //freopen("input","r",stdin);
    scanf("%d%d",&n,&m);
    if (n>40||m>40) return 0;
    for (i=0;i<n;i++) {
        for (j=0;j<m;j++) {
            scanf("%d",&arr[i][j]);
            arr[i][j]--;
        }
    }
    for (i=0;i<n;i++) {
        for (j=0;j<m;j++) {
            if (arr[i][j]>=0) arr[i][j] = p++;
        }
    }
    if (p>10) return 0;
    for (i=0;i<n;i++) {
        for (j=0;j<m+1;j++) {
            int a;
            scanf("%d",&a);
            for (k=0;k<(1<<p);k++) {
                lis[rval(val(i,j),k)].push_back(edge(rval(val(i+1,j),k),a,0));
                lis[rval(val(i+1,j),k)].push_back(edge(rval(val(i,j),k),a,0));
            }
        }
    }
    for (i=0;i<n+1;i++) {
        for (j=0;j<m;j++) {
            int a, x = 0;
            scanf("%d",&a);
            for (k=i;k<n;k++) {
                if (arr[k][j]>=0) x += (1<<arr[k][j]);
            }
            for (k=0;k<(1<<p);k++) {
                lis[rval(val(i,j),k)].push_back(edge(rval(val(i,j+1),k^x),a,x));
                lis[rval(val(i,j+1),k)].push_back(edge(rval(val(i,j),k^x),a,x));
            }
        }
    }
    dijk();
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
wall.cpp: In constructor 'edge::edge(int, ll, int)':
wall.cpp:6:18: warning: 'edge::w' will be initialized after [-Wreorder]
    6 |     int j, x; ll w;
      |                  ^
wall.cpp:6:12: warning:   'int edge::x' [-Wreorder]
    6 |     int j, x; ll w;
      |            ^
wall.cpp:8:5: warning:   when initialized here [-Wreorder]
    8 |     edge(int j, ll w, int x):j(j),w(w),x(x){}
      |     ^~~~
wall.cpp: In function 'void dijk()':
wall.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (i=0;i<lis[here].size();i++) {
      |                  ~^~~~~~~~~~~~~~~~~
wall.cpp:29:12: warning: unused variable 'w' [-Wunused-variable]
   29 |         ll w = -tmp.first;
      |            ^
wall.cpp: In function 'int main()':
wall.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
wall.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |             scanf("%d",&arr[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
wall.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |             scanf("%d",&a);
      |             ~~~~~^~~~~~~~~
wall.cpp:71:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |             scanf("%d",&a);
      |             ~~~~~^~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |