Contest Duration: ~ (local time) (480 minutes)

Submission #12881409

Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

#define N 30
int a[N+2][N+2];
int disX[4] = {1,0,-1,0};
int disY[4] = {0,1,0,-1};
int sum = 0;

inline void input(){
Rep(i,N) Rep(j,N) {
Scd(a[i+1][j+1]);
// a[i+1][j+1] = (i*419+j*312)%100;
sum+=a[i+1][j+1];
}
}

double neighbors( int bx, int by, int depth = 16 ){
if( depth==0 ) return 0;
if( a[bx][by] < 2 ) return 0;
double ret = 0;
Rep(i,4){
int bbx = bx-disX[i];
int bby = by-disY[i];
if( a[bbx][bby]+1 == a[bx][by] )
ret += 5*neighbors(bbx,bby,depth-1) + 101;
}
return ret;
}

double eval( int bx, int by, int px, int py ){
if( a[px][py] == 0 ) return -1e12;
double ret = a[px][py];
if( abs(bx-px) + abs(by-py) == 1 && a[px][py] == a[bx][by] ) ret += 1e11;
ret += neighbors(px,py);
return ret;
}

void run( int x, int y ){
printf ("%d %d\n", x, y );
a[x][y]--;
// Rep(i,N) Rep(j,N){
//     printf ("%d%s", a[i+1][j+1], j == N-1 ? "\n" : "," );
// }
// printf ("\n");
// int k;
// Scd(k);
}

void solve(){
int bestX = 0;
int bestY = 0;
int way = 0;

while(sum--){
int nextX = -1;
int nextY = -1;
double bestScore = -1e12;
Repe(preX,N+1,1) Repe(preY,N+1,1){
double preScore = eval(bestX,bestY,preX,preY);
// printf ("%lld,%lld = %dpts\n", preX, preY, preScore );
if( bestScore < preScore ){
bestScore = preScore;
nextX = preX;
nextY = preY;
}
}
if( abs(nextX-bestX) + abs(nextY-bestY) != 1 ||
a[nextX][nextY] != a[bestX][bestY] ) way++;
// printf ("---#%d.---\n", way );
run(nextX,nextY);
bestX = nextX;
bestY = nextY;
}

// printf ("%d\n", way );

}

int main() {

input();
solve();

return 0;
}

#### Submission Info

Submission Time 2020-05-06 13:24:29+0900 A - 高橋君の山崩しゲーム dekomori_sanae C++14 (GCC 5.4.1) 813150 3144 Byte AC 408 ms 512 KB

#### Compile Error

./Main.cpp: In function ‘void input()’:
./Main.cpp:55:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
Scd(a[i+1][j+1]);
^

#### Test Cases

Set Name Score / Max Score Test Cases