Language: C++

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
// void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
// void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;

int n=40,m=100,b=300;
int dx[5]={0,-1,0,1,0},dy[5]={0,0,1,0,-1};

vector<vec> initsquare(40,vec(40));
int gx,gy;
struct robot{
    int x,y,c;
};
vector<robot> robots;
struct State{
    int cnt=0;
    int score;
    vector<vec> square;
    vector<vec> res;
    State(){
        square=res=vector<vec>(40,vec(40));
    }
    void write(){
        cout<<cnt<<endl;
        rep(i,40)rep(j,40){
            if(square[i][j]&&square[i][j]!=5){
                cout<<i<<" "<<j<<" ";
                int c=square[i][j];
                if(c==1)cout<<'U';
                else if(c==2)cout<<'R';
                else if(c==3)cout<<'D';
                else cout<<'L';
                cout<<endl;
            }
        }
    }
    // void write(string filename){
    //     ofstream ofs(filename);
    //     ofs<<cnt<<endl;
    //     rep(i,40)rep(j,40){
    //         if(square[i][j]&&square[i][j]!=5){
    //             ofs<<i<<" "<<j<<" ";
    //             int c=square[i][j];
    //             if(c==1)ofs<<'U';
    //             else if(c==2)ofs<<'R';
    //             else if(c==3)ofs<<'D';
    //             else ofs<<'L';
    //             ofs<<endl;
    //         }
    //     }
    // }
};
int evaluate(State &state){
    vector<vec> visited(40,vec(40));
    int score=-10*state.cnt;
    rep(i,m){
        vector<vec> tmp(40,vec(40));
        int x=robots[i].x,y=robots[i].y,c=robots[i].c;
        while(1){
            if(tmp[x][y])break;
            if(state.square[x][y]==5){
                state.res[x][y]+=1;
                break;
            }
            tmp[x][y]=1;visited[x][y]=1;
            if(x==gx&&y==gy){
                score+=1000;
                break;
            }
            if(state.square[x][y])c=state.square[x][y];
            x=(x+dx[c]+n)%n;
            y=(y+dy[c]+n)%n;
        }
    }
    rep(i,40)rep(j,40)score+=visited[i][j];
    return state.score=score;
}
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll MAXVALUE){
    uniform_int_distribution<> rand(0, INT_MAX - 1);
    if(MAXVALUE==0)return 0;
    return rand(mt)%MAXVALUE;
}
double drnd(){
    uniform_int_distribution<> rand(0, INT_MAX - 1);
    return (double)rand(mt)/INT_MAX;
}
struct Annealing{
    int bestscore,initscore;
    State initState,bestState;
    void Init(){
        initState.cnt=0;initState.square=initsquare;
        bestscore=initscore=evaluate(initState);
    }
    State rnd_locate(State state){
        int x,y;
        do{
            x=rnd(40);y=rnd(40);
        }while(state.square[x][y]==5);
        if(state.square[x][y]==0)state.cnt++;
        state.square[x][y]=rnd(5);
        if(state.square[x][y]==0)state.cnt--;
        evaluate(state);
        return state;
    }
    double probability(int next,int now,double r){
        return exp((double)(next-now)/r/now);
    }
    void go(double limit){
        clock_t startTime=clock();
        Init();
        State state=bestState=initState;
        while((double)(clock()-startTime)/CLOCKS_PER_SEC<limit){
            State nextState;
            int P=rnd(100);
            nextState=rnd_locate(state);
            int next=nextState.score;
            if(next>bestscore){
                bestscore=next;
                bestState=nextState;
                state=nextState;
            }
            else if(drnd()<probability(next,state.score,pow(1.0,clock()-startTime)/CLOCKS_PER_SEC/limit)){
                state=nextState;
            }
        }
    }
    void write(){
        bestState.write();
    }
    void write(string filename){bestState.write(filename);}
};

main(){
    int n=in(),m=in(),b=in();
    gx=in(),gy=in();
    rep(i,m){
        int x=in(),y=in();char c;
        cin>>c; int C;
        if(c=='U')C=1;
        else if(c=='R')C=2;
        else if(c=='D')C=3;
        else C=4;
        robots.pb(robot{x,y,C});
    }

    rep(i,b){
        int x=in(),y=in();
        initsquare[x][y]=5;
    }
    Annealing ann;
    ann.go(2.985);
    ann.write();
    ann.write("C:/Users/kenma/Desktop/sagyou/output1.txt");
}

Compiler output:
a.cc: In member function 'void Annealing::write(std::string)':
a.cc:177:48: error: no matching function for call to 'State::write(std::string&)'
  177 |     void write(string filename){bestState.write(filename);}
      |                                 ~~~~~~~~~~~~~~~^~~~~~~~~~
a.cc:69:10: note: candidate: 'void State::write()'
   69 |     void write(){
      |          ^~~~~
a.cc:69:10: note:   candidate expects 0 arguments, 1 provided
a.cc: At global scope:
a.cc:180:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  180 | main(){
      | ^~~~