Language: C++

#include <vector>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <typeinfo>
#include <queue>
#include <set>
#include <sstream>
#include <limits.h>

using namespace std;

#define RSORT(c) sort((c).begin(),(c).end(),std::greater<int>())
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SORT(c) sort((c).begin(),(c).end())

static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
#define MAX 200000
#define SENTINEL 10000000000
typedef long long ll;

void c1(){
  int l = 10;
  string s;
  cin >> s;
  //s[4] = "8";
  s.replace(3, 1, "8");
  cout << s << endl;
}

void c2(){
  int n;
  cin >> n;
  int tmp;
  vector<int> vec;
  REP(i,n){
    cin >> tmp;
    vec.push_back(tmp);
  }
  SORT(vec);
    //erace(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() << endl;
}

void c3(){
  int n;
  int m;
  cin >> n;
  cin >> m;
  int x,y,z;
  x=y=z=0;
  bool xf,yf,zf;
  xf=true;
  yf=zf=false;
  int now=0;
  REP(i,n){
    if(xf == true){
      if(now + 10000 > m){
        xf = false;
        yf=true;
      }
      else{
        x++;
        now += 10000;
      }
    }
    if(yf == true){
      if(now + 5000 > m){
        yf = false;
        zf=true;
      }
      else{
        y++;
        now += 5000;
      }
    }
    if(zf == true){
      if(now + 1000 > m){
        zf = false;
        break;
      }
      else{
        z++;
        now += 1000;
      }
    }
  }
  int ss = 0;
  ss = x+y+z;
  //cout << x << y << z << endl;
  //cout << ss << endl;
  bool dame = false;
  if (now < m){
    dame=true;
    //cout << -1 << " " <<  -1 << " " << -1;
  }
  int amari = n - ss;
  yf=true;
  xf=zf=false;
  if(x>0){
    y+=2*x;
    amari-=x;
    x=0;
  }
  while(amari > 0){
    if(xf){
      if(x - amari> 0){
        int diff=x-amari;
        x-= amari;
        y+=2*diff;
        amari=0;
        //cout << "a";
        //cout <<  "a";
      }
      else{
        xf=false;
        //yf=true;
        //dame=true;
        break;
      }
    }
    //cout <<"a" <<  amari << endl;
    if(yf){
      if(y>0 && amari > 3){
        int sho = amari / 4;
        int wei = amari % 4;
        y-=sho;
        z+=5*sho;
        amari-=4*sho;
      }
      else{
        yf=false;
        xf=true;
        //break;
        //dame=true;
        //break;
      }
    }
                   //cout << "b" << amari << endl;
  }
  if (amari > 0 && dame == false){
    if(amari==2){
      x+=2;
      y-=5;
      z+=5;
    }
    else{
      x+=1;
      y-=3;
      z+=5;
    }
    }
    //dame=false;
  if (dame==true){
    cout << -1 << " " <<  -1 << " " << -1 << endl;
  }
  else{
    cout << x << " " <<  y << " " << z << endl;
  }
}

void c4(){
  int n;
  int m;
  cin >> n;
  cin >> m;
  int x,y,z;
  x=y=z=0;
  bool xf,yf,zf;
  xf=true;
  yf=zf=false;
  int now=0;
  REP(i,n){
    if(xf == true){
      if(now + 10000 > m){
        xf = false;
        yf=true;
      }
      else{
        x++;
        now += 10000;
      }
    }
    if(yf == true){
      if(now + 5000 > m){
        yf = false;
        zf=true;
      }
      else{
        y++;
        now += 5000;
      }
    }
    if(zf == true){
      if(now + 1000 > m){
        zf = false;
        break;
      }
      else{
        z++;
        now += 1000;
      }
    }
  }
  int ss = 0;
  ss = x+y+z;
  //cout << x << y << z << endl;
  //cout << ss << endl;
  bool dame = false;
  int xn,yn,zn;
  if (now < m){
    dame=true;
    //cout << -1 << " " <<  -1 << " " << -1;
  }
  else{
    //int nokori= n - ss;
    //int sho = nokori/4;
    //int amari =nokori%4;
    zn = m / 1000;
    //int xn,yn;
    xn=yn=0;
    while(zn +yn >= n && zn >= 0){
      zn-=5;
      yn+=1;
    }
    //if (zn<0){
      zn+=5;
      yn--;
      //}
      int diff=n-zn;
      while(yn + xn >= diff && yn >= 0){
        yn-=2;
        xn+=1;
      }
      //cout << xn << " " << yn << " " << zn << endl;
        yn+=2;
        xn--;
      if( xn + yn + zn != n){
        dame = true;
      }
    }
  if (zn*1000 + yn*5000 + xn*10000 != m){
    dame =true;
  }
  if (dame==true){
    cout << -1 << " " <<  -1 << " " << -1 << endl;
  }
  else{
    cout << xn << " " <<  yn << " " << zn << endl;
  }
}

void c5(){
  int n,m;
  cin >> n >> m;
  bool dame = false;
  int xn,yn,zn;
    //int nokori= n - ss;
    //int sho = nokori/4;
    //int amari =nokori%4;
    zn = m / 1000;
    //int xn,yn;
    xn=yn=0;
    while(zn +yn >= n && zn >= 0){
      zn-=5;
      yn+=1;
    }
    //if (zn<0){
    zn+=5;
    yn--;
    //}
    int diff=n-zn;
    while(yn + xn >= diff && yn >= 0){
      yn-=2;
      xn+=1;
    }
    //cout << xn << " " << yn << " " << zn << endl;
    yn+=2;
    xn--;
    if( xn + yn + zn != n){
      dame = true;
    }
  if (zn*1000 + yn*5000 + xn*10000 != m){
    dame =true;
  }
  if (dame==true){
    cout << -1 << " " <<  -1 << " " << -1 << endl;
  }
  else{
    cout << xn << " " <<  yn << " " << zn << endl;
  }
  
}

void c6(){
  int n,h;
  cin >> n >> h;
  vector<int> a,b,vec;
  int tmp1,tmp2;
  REP(i,n){
    cin >> tmp1 >> tmp2;
    a.push_back(tmp1);
    b.push_back(tmp2);
    vec.push_back(tmp1);
    vec.push_back(tmp2);
  }
  //pairの入ったvectorの定義
  typedef std::pair<int, int> pair;
  std::vector<pair> pair_vec;

  //pair入りvectorに添字とvectorの中身を挿入
  //std::cout << "before sort" << std::endl;
  for(int i=0; i<vec.size(); i++){
    pair_vec.push_back(pair(i, vec[i]));
    //std::cout << i << " " << vec[i] << std::endl;
  }

  //ラムダ式で比較式を書く
  std::sort(
            pair_vec.begin(),
            pair_vec.end(),
            [](const pair& x, const pair& y){return x.second > y.second;}
            );

  // std::cout << "before sort" << std::endl; 
  // for(auto& i:index){
  //  std::cout << i << " " << vec[i] << std::endl;
  // }
  int num=0;
  int attacker=0;
  for(auto& i: pair_vec){
    h-=i.second;
    num++;
    //std::cout << i.first << " " << i.second << std::endl;

    if(i.first%2 == 0){
      attacker=i.second;
      break;
    }
    if(h<=0){
      break;
    }
  }

  if(h<=0){
    cout << num << endl;
  }
  else{
    int sho = h / attacker;
    int amari = h % attacker;
    if(amari > 0){
      sho++;
    }
    cout << num + sho << endl;
  }


}

void c7(){
  int n,a;
  cin >> n >> a;
  int sho,amari;
  amari = n % 500;
  if(amari == 0){
    cout << "Yes" << endl;
  }
  else{
    if(amari <= a){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

void c8(){
  int n;
  cin >> n;
  vector<int> vec;
  int tmp;
  REP(i,n){
    cin >> tmp;
    vec.push_back(tmp);
  }
  RSORT(vec);
  int ali=0;
  int bob=0;
  REP(i,n){
    //cout << vec[i] << endl;
    if(i%2==0){
      ali+=vec[i];
    }
    else{
      bob+=vec[i];
    }
  }
  cout << ali-bob << endl;

}

void c9(){
  vector<int> c;
  int tmp;
  REP(i,9){
    cin >> tmp;
    c.push_back(tmp);
  }
  //vector<int> a,b;
  int a[3],b[3];
  a[0] = 0;
  b[0] = c[0] - a[0];
  int val;
  b[1] = c[1] - a[0];
  b[2] = c[2] - a[0];
  a[1] = c[3*1] - b[0];
  a[2] = c[3*2] - b[0];
  bool flg=true;
  FOR(j,1,3){
    FOR(i,1,3){
      val = c[j*3 + i] - b[i];
      //cout << i << " " << j << " " << c[j*3+i] << b[i] << " " <<  a[j] << val << endl;
      if(val != a[j]){
        flg = false;
      }
    }
  }
  if(flg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}



// A C++ program for Dijkstra's single source shortest path algorithm.
// The program is for adjacency matrix representation of the graph

  
// Number of vertices in the graph
#define V 50
  
// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
   // Initialize min value
   int min = INT_MAX, min_index;
  
   for (int v = 0; v < V; v++)
     if (sptSet[v] == false && dist[v] <= min)
         min = dist[v], min_index = v;
  
   return min_index;
}

// A utility function to print the constructed distance array
int printSolution(int dist[], int n)
{
   printf("Vertex   Distance from Source\n");
   for (int i = 0; i < V; i++)
      printf("%d tt %d\n", i, dist[i]);
}

struct data{
  vector<int> a;
};
  
// Funtion that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
vector<int> dijkstra(int graph[V][V], int src, int max_num)
{
     int dist[V];     // The output array.  dist[i] will hold the shortest
                      // distance from src to i
  
     bool sptSet[V]; // sptSet[i] will true if vertex i is included in shortest
                     // path tree or shortest distance from src to i is finalized
  
     // Initialize all distances as INFINITE and stpSet[] as false
     //vector<vector<int>> hoge;
     //vector<int> idx;
     //vector<int> value[V];
     int pi[V];

     vector<int> path;
     //path.push_back(3);
     for (int i = 0; i < V; i++)
        dist[i] = INT_MAX, sptSet[i] = false;
  
     // Distance of source vertex from itself is always 0
     dist[src] = 0;
  
     // Find shortest path for all vertices
     for (int count = 0; count < V-1; count++)
     {
       // Pick the minimum distance vertex from the set of vertices not
       // yet processed. u is always equal to src in first iteration.
       int u = minDistance(dist, sptSet);
  
       // Mark the picked vertex as processed
       sptSet[u] = true;
       //path.push_back(u);
  
       // Update dist value of the adjacent vertices of the picked vertex.

       for (int v = 0; v < V; v++)
  
         // Update dist[v] only if is not in sptSet, there is an edge from 
         // u to v, and total weight of path from src to  v through u is 
         // smaller than current value of dist[v]

         if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX 
             && dist[u]+graph[u][v] < dist[v]){
           dist[v] = dist[u] + graph[u][v];
            //cout << v << " ";
            //value[u].push_back()
            //idx.push
            pi[v] = u;
         }
     }
     int end = max_num - 1;
     //cout << end << endl;
     while(pi[end]!=0){
       end = pi[end];
       path.push_back(end);
       //cout << end << " ";
     }
  
     // print the constructed distance array
     //printSolution(dist, V);
     return path;
}


int graph[V][V];

int d1(){
  int h,w;
  cin >> h >> w;
  char s[50][50];
  char tmp;
  REP(i,h){
    REP(j,w){
      cin >> tmp;
      s[i][j] = tmp;
    }
  }
 
  REP(k,h*w){
    graph[k][k] = 0;
    int i = k / w;
    int j = k % w;
    if(j>0){
      if(s[i][j]=='.'){
        if(s[i][j-1] =='.'){
          graph[k][k-1] = 1;
        }
        else{
          graph[k][k-1] = 0;
        }
      }
      else{
        graph[k][k-1] = 0;
      }
    }
    if(j<w){
      if(s[i][j]=='.'){
        if(s[i][j+1] =='.'){
          graph[k][k+1] = 1;
        }
        else{
          graph[k][k+1] = 0;
        }
      }
      else{
        graph[k][k+1] = 0;
      }
    }
    if(i>0){
      if(s[i][j]=='.'){
        if(s[i-1][j] =='.'){
          graph[k][k-w] = 1;
        }
        else{
          graph[k][k-w] = 0;
        }
      }
      else{
        graph[k][k-w] = 0;
      }
    }
    if(i<h){
      if(s[i][j]=='.'){
        if(s[i+1][j] =='.'){
          graph[k][k+w] = 1;
        }
        else{
          graph[k][k+w] = 0;
        }
      }
      else{
        graph[k][k+w] = 0;
      }
    }
  }
  vector<int> path;
  //path = dijkstra(graph,0,h*w);
  int memo[V+2][V+2];
  REP(i,h+2){
    REP(j,w+2){
      memo[i][j] = INT_MAX-1;
    }
  }
  //cout << INT_MAX;
  memo[h][w] = 0;
  int pi[2500];
  FOR(it,0,h){
    FOR(jt,0,w){
      int i = h - it;
      int j = w - jt;
      if(memo[i][j] < INT_MAX-1){
        continue;
      }
      if(s[i-1][j-1] == '#'){
        continue;
      }
      //cout << i << j << endl;
      //cout << memo[i-1][j] + 1;
      int min_memo[4] = {memo[i-1][j] + 1, memo[i][j-1] + 1, memo[i+1][j] + 1, memo[i][j+1] +1  };
      //memo[i][j] = min_memo;
      int minval = INT_MAX;
      int min_index = -1;
      REP(p,4){
        if(min_memo[p] < minval){
          minval = min_memo[p];
          min_index = p;
        }
      }
      if(min_index != -1){
        memo[i][j] = minval;
      }
      REP(p,4){
        //cout << min_memo[p] << " ";
      }
      //cout << min_index << " " << minval << endl;
      if(min_index == 0){
        pi[(i-1)*w + j-1] = (i-2)*w + j-1;
      }
      else if(min_index == 1){
        pi[(i-1)*w + j-1] = (i-1)*w + j-2;
      }
      else if(min_index == 2){
        pi[(i-1)*w + j-1] = (i)*w + j-1;
      }
      else if(min_index == 3){
        pi[(i-1)*w + j-1] = (i-1)*w + j;
      }
    }
  }
  REP(i,h){
    REP(j,w){
      //cout << pi[i*w + j] << " ";
    }
  }
  //cout << endl;
  int start = 0;
  int leng = 0;
  while(pi[start]!=0){
    start = pi[start];
    leng++;
  }

  if(start != h*w-1){
    cout << -1 << endl;
  }
  else{
    int rs = h*w - 2;
    REP(i,h){
      REP(j,w){
        if(s[i][j]=='#'){
          rs--;
        }
      }
    } 
    cout << rs - leng + 1; << endl;
  }

  path.push_back(3);
  if(path.size() == 0){
    //cout << -1 << endl;
  }
  else{
    REP(i,path.size()){
      //cout << path[i] << " ";
    }
    //cout << endl;
    int rs = h*w - 2;
    REP(i,h){
      REP(j,w){
        if(s[i][j]=='#'){
          rs--;
        }
      }
    }
    rs -= path.size();
    //cout << rs << endl;
  }
}

int c10(){
  int h,w;
  cin >> h >> w;
  char s[50][50];
  char tmp;
  REP(i,h){
    REP(j,w){
      cin >> tmp;
      s[i][j] = tmp;
    }
  }
  REP(k,h*w){
  REP(i,h){
    REP(j,w){
      //cout << s[i][j]<< " ";
      if(k==i*w+j){
        graph[k][k] = 0;
      }
      else if(s[i][j] == '.'){
        if(i>0){
          if(s[i-1][j] == '#'){
            graph[k][j] = 0;
          }
          else{
            graph[i][j] = 1;
          }
        }
        if(i<h-1){
          if(s[i+1][j] == '#'){
            //graph[i+1][j] = 0;
          }
          else{
            //graph[i+1][j] = 1;
          }
        }
        if(j>0){
          if(s[i][j-1] == '#'){
            graph[k][j] = 0;
          }
          else{
            graph[i][j] = 1;
          }
        }
        if(j<w-1){
          if(s[i][j+1] == '#'){
            //graph[i][j+1] = 0;
          }
          else{
            //graph[i][j+1] = 1;
          }
        }
      }
    }
    //cout << endl;
  }
  }
  REP(i,h){
    REP(j,w){
      cout << graph[i][j] << " ";
    }
    cout << endl;
  }

}

int main(){
  //c1();
  //c5();
  //c6();
  //c7();
  //c8();
  //c9();
  d1();
  return 0;
}


Compiler output:
a.cc: In function 'int printSolution(int*, int)':
a.cc:474:1: warning: no return statement in function returning non-void [-Wreturn-type]
  474 | }
      | ^
a.cc: In function 'int d1()':
a.cc:696:28: error: expected primary-expression before '<<' token
  696 |     cout << rs - leng + 1; << endl;
      |                            ^~
a.cc:719:1: warning: no return statement in function returning non-void [-Wreturn-type]
  719 | }
      | ^
a.cc: In function 'int c10()':
a.cc:784:1: warning: no return statement in function returning non-void [-Wreturn-type]
  784 | }
      | ^