Language: Java

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

ll dp[3001][3001][4][4];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for(int i=0; i<3001; i++){
    for(int j=0; j<3001; j++){
      for(int k=0; k<4; k++){
        for(int l=0; l<4; l++){
          dp[i][j][k][l] = 0;
        }
      }
    }
  }
  int R,C,K;
  cin >> R >> C >> K;
  vector<vector<ll>> G(R,vector<ll> (C,0));
  for(int i=0; i<K; i++){
    int r,c,v;
    cin >> r >> c >> v;
    r--;c--;
    G[r][c] = v;
  }
  for(int i=0; i<R; i++){
    for(int j=0; j<C; j++){
      for(int k=0; k<=3; k++){
        for(int l=0; l<=3; l++){
          // 行移動
          chmax(dp[i+1][j][k][0],dp[i][j][k][l]);
          if(l != 3){
            chmax(dp[i+1][j][k+1][0],dp[i][j][k][l] + G[i][j]);
          }
          // 列移動
          chmax(dp[i][j+1][0][l],dp[i][j][k][l]);
          if(k != 3){
            chmax(dp[i][j+1][0][l+1],dp[i][j][k][l] + G[i][j]);
          }
        }
      }
    }
  }
  ll ans = 0;
  for(int i=0; i<=3; i++){
    for(int j=0; j<=3; j++){
      chmax(ans,dp[R][C-1][i][j]);
      chmax(ans,dp[R-1][C][i][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#pragma GCC optimize("Ofast")
^
Main.java:2: error: illegal character: '#'
#include <iostream> // cout, endl, cin
^
Main.java:1: error: unnamed classes are a preview feature and are disabled by default.
#pragma GCC optimize("Ofast")
        ^
  (use --enable-preview to enable unnamed classes)
Main.java:3: error: illegal character: '#'
#include <string> // string, to_string, stoi
^
Main.java:4: error: illegal character: '#'
#include <vector> // vector
^
Main.java:5: error: illegal character: '#'
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
^
Main.java:6: error: illegal character: '#'
#include <utility> // pair, make_pair
^
Main.java:7: error: illegal character: '#'
#include <tuple> // tuple, make_tuple
^
Main.java:8: error: illegal character: '#'
#include <cstdint> // int64_t, int*_t
^
Main.java:9: error: illegal character: '#'
#include <cstdio> // printf
^
Main.java:10: error: illegal character: '#'
#include <map> // map
^
Main.java:11: error: illegal character: '#'
#include <queue> // queue, priority_queue
^
Main.java:12: error: illegal character: '#'
#include <set> // set
^
Main.java:13: error: illegal character: '#'
#include <stack> // stack
^
Main.java:14: error: illegal character: '#'
#include <deque> // deque
^
Main.java:15: error: illegal character: '#'
#include <unordered_map> // unordered_map
^
Main.java:16: error: illegal character: '#'
#include <unordered_set> // unordered_set
^
Main.java:17: error: illegal character: '#'
#include <bitset> // bitset
^
Main.java:18: error: illegal character: '#'
#include <cctype> // isupper, islower, isdigit, toupper, tolower
^
Main.java:19: error: illegal character: '#'
#include <iomanip> // setprecision
^
Main.java:20: error: illegal character: '#'
#include <complex> // complex
^
Main.java:21: error: illegal character: '#'
#include <functional>
^
Main.java:22: error: illegal character: '#'
#include <math.h> 
^
Main.java:23: error: illegal character: '#'
#define enld '\n'
^
Main.java:25: error: '.class' expected
using ll = long long;
                ^
Main.java:26: error: '.class' expected
using P = pair<int,int>;
                  ^
Main.java:26: error: <identifier> expected
using P = pair<int,int>;
                   ^
Main.java:27: error: class, interface, enum, or record expected
constexpr ll INF = 1e18;
^
Main.java:28: error: class, interface, enum, or record expected
constexpr int inf = 1e9;
^
Main.java:30: error: class, interface, enum, or record expected
constexpr ll mod2 = 998244353;
^
Main.java:31: error: class, interface, enum, or record expected
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
^
Main.java:32: error: class, interface, enum, or record expected
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
^
Main.java:33: error: class, interface, enum, or record expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
^
Main.java:33: error: '{' expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                ^
Main.java:33: error: illegal start of type
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                 ^
Main.java:33: error: > or ',' expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                          ^
Main.java:33: error: illegal start of type
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                                                 ^
Main.java:34: error: class, interface, enum, or record expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
^
Main.java:34: error: '{' expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                ^
Main.java:34: error: illegal start of type
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                 ^
Main.java:34: error: <identifier> expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                      ^
Main.java:34: error: <identifier> expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                          ^
Main.java:34: error: illegal start of type
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                                                 ^
Main.java:37: error: class, interface, enum, or record expected
ll dp[3001][3001][4][4];
^
Main.java:40: error: not a statement
  ios::sync_with_stdio(false);
  ^
Main.java:52: error: not a statement
  cin >> R >> C >> K;
                ^
Main.java:53: error: not a statement
  vector<vector<ll>> G(R,vector<ll> (C,0));
                       ^
Main.java:53: error: not a statement
  vector<vector<ll>> G(R,vector<ll> (C,0));
                               ^
Main.java:53: error: not a statement
  vector<vector<ll>> G(R,vector<ll> (C,0));
                                     ^
Main.java:56: error: not a statement
    cin >> r >> c >> v;
                  ^
Main.java:85: error: not a statement
  cout << ans << "\n";
              ^
Main.java:40: error: ';' expected
  ios::sync_with_stdio(false);
                      ^
Main.java:53: error: ';' expected
  vector<vector<ll>> G(R,vector<ll> (C,0));
                      ^
Main.java:53: error: ';' expected
  vector<vector<ll>> G(R,vector<ll> (C,0));
                        ^
Main.java:53: error: ';' expected
  vector<vector<ll>> G(R,vector<ll> (C,0));
                                   ^
Main.java:53: error: ';' expected
  vector<vector<ll>> G(R,vector<ll> (C,0));
                                      ^
56 errors