LYDSY模拟赛day9 2048

时间:2022-10-14 15:20:13

LYDSY模拟赛day9 2048

LYDSY模拟赛day9 2048

LYDSY模拟赛day9 2048

/*
大模拟题,做的时候思路还是比较清晰的
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
using namespace std;
const int maxn = ;
ll read(){
ll x=,f=;
char ch=getchar();
while(!(ch>=''&&ch<='')){if(ch=='-')f=-;ch=getchar();};
while(ch>=''&&ch<=''){x=x*+(ch-'');ch=getchar();};
return x*f;
}
int n,m;
int dx[] = {,,-,};
int dy[] = {-,,,};
int flag[][];
bool vis[][];
ll mp[][],d,k,v;
ll ans1,ans2;
ll judge(int y,int x,ll val){
if(y < || y > n || x < || x > n || vis[y][x]) return -;
if(!mp[y][x]) return val;
if(mp[y][x] == val) return val*;
return -;
}
bool tran(int op){
memset(vis,false,sizeof(vis));
bool cg = false;
int st1,ed1,dr1,st2,ed2,dr2;
int ny,nx,cy,cx;
ll tmp,rst;
d = read();
k = read();
v = read();
if(d == ){
st1 = n;
ed1 = ;
dr1 = -;
}else{
st1 = ;
ed1 = n;
dr1 = ;
}
if(d == ){
st2 = n;
ed2 = ;
dr2 = -;
}else{
st2 = ;
ed2 = n;
dr2 = ;
}
for(int i = st1;;i += dr1){
for(int j = st2;;j += dr2){
tmp = mp[i][j];
cy = i;
cx = j;
if(tmp)while(){
ny = cy + dy[d];
nx = cx + dx[d];
rst = judge(ny,nx,tmp);
if(rst == -) break;
else{
cg = true;
mp[cy][cx] = ;
mp[ny][nx] = rst;
if(rst != tmp){
ans2 += rst;
vis[ny][nx] = true;
break;
}
cy = ny;
cx = nx;
}
}
if(j == ed2) break;
}
if(i == ed1) break;
}
if(!cg) return false;
ans1++;
ll r = ;
memset(flag,,sizeof(flag));
fo(i,,n){
fo(j,,n){
if(!mp[i][j]) flag[i][j] = ++r;
}
}
fo(i,,n){
fo(j,,n){
if(flag[i][j] == + k%r) mp[i][j] = v;
}
}
return true;
}
int main(){
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
n = read();
m = read();
int x,y,v;
y = read();x = read();v = read();mp[y][x] = v;
y = read();x = read();v = read();mp[y][x] = v;
fo(op,,m){
if(!tran(op)) break;
}
cout<<ans1<<endl<<ans2<<endl;
return ;
}