Submission #338817

# Submission time Handle Problem Language Result Execution time Memory
338817 2020-12-24T03:33:54 Z tengiz05 Ants (IZhO12_ants) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool ckmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool ckmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 105;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N][N], n, m, k, T;
int X[N], Y[N], dir[N];
int d1[4] = {1, 0, -1, 0};
int d2[4] = {0, 1, 0, -1};
void solve(int test_case){
	int i, j;
	cin >> n >> m >> k >> T;
	for(i=0;i<k;i++){
		cin >> X[i] >> Y[i] >> dir[i];
		dir[i]--;
	}
	for(int tt=1;tt<=T;tt++){
		for(i=0;i<k;i++){
			for(j=0;j<k;j++){
				if(i==j)continue;
				if(dir[i] == 1 && dir[j] == 3){
					if(X[i] == X[j] && Y[j]-Y[i] == 2)Y[i]++,Y[j]--,swap(dir[i],dir[j]);
					else if(X[i]==X[j] && Y[j]-Y[i] == 1)Y[i]++,Y[j]--,swap(dir[i], dir[j]);
					else continue;
					if(X[i] == 0)(dir[i]+=2)%=4;
					if(Y[i] == 0)(dir[i]+=2)%=4;
					if(X[i] == n)(dir[i]+=2)%=4;
					if(Y[i] == m)(dir[i]+=2)%=4;
				}
				if(dir[i] == 0 && dir[j] == 2){
					if(Y[i] == Y[j] && X[j]-X[i] == 2)X[i]--,X[j]++,swap(dir[i],dir[j]);
					else if(Y[i]==Y[j] && X[j]-X[i] == 1)X[i]--,X[j]++,swap(dir[i], dir[j]);
					else continue;
					if(X[i] == 0)(dir[i]+=2)%=4;
					if(Y[i] == 0)(dir[i]+=2)%=4;
					if(X[i] == n)(dir[i]+=2)%=4;
					if(Y[i] == m)(dir[i]+=2)%=4;
				}
			}
		}
		for(i=0;i<k;i++){
			X[i] += d1[dir[i]];
			Y[i] += d2[dir[i]];
			if(X[i] <= 0)(dir[i]+=2)%=4;
			if(Y[i] <= 0)(dir[i]+=2)%=4;
			if(X[i] >= n)(dir[i]+=2)%=4;
			if(Y[i] >= m)(dir[i]+=2)%=4;
			
		//	cout << X[i] << ' ' << Y[i] << ' ' << dir[i]+1 << '\n';
		}//cout << '\n';
	}
	for(i=0;i<k;i++){
		cout << X[i] << ' ' << Y[i] << ' ' << dir[i]+1 << '\n';
	}
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -