Submission #90291

# Submission time Handle Problem Language Result Execution time Memory
90291 2018-12-21T06:00:07 Z YottaByte Ants (IZhO12_ants) C++14
0 / 100
2 ms 988 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ok puts("OK");

const int N = 105;
int n, m, k, t;

vector < int > a[N][N], b[N][N];
vector < pair < pair < int, int >, pair < int, int > > > v;

int reversed( int d )
{
	int res = (d + 2) % 4;
	if(res)
	return res;
	else return 4;
}

inline bool can( int x, int y, int &d )
{
	x += (d == 1);
	x -= (d == 3);
	y += (d == 2);
	y -= (d == 4);
	
	int revd = reversed(d);
	if( a[x][y].size() )
	{
		for(int i : a[x][y])
		{
			if( i == revd || i == d )
			{
				d = revd;
				return 0;
			}
		}
		return 1;
	}
	else
	{
		x += (d == 1);
		x -= (d == 3);
		y += (d == 2);
		y -= (d == 4);
		
		for(int i : a[x][y])
		{
			//cout << x << " " << y << " " << i << " " << d << endl;
			if(i == revd)
			{
				d = revd;
				return 1;
			}
		}
	}
	return 1;
}

inline void bor( int x, int y, int &d )
{
	if(d == 1 && x == n)
	{
		d = reversed(d);
	}
	
	else if(d == 2 && y == m)
	{
		d = reversed(d);
	}
	
	else if(d == 3 && x == 0)
	{
		d = reversed(d);
	}
	
	else if(d == 4 && y == 0)
	{
		d = reversed(d);
	}
}

inline void move( int x, int y, int &d, int id )
{
	b[x][y].pop_back();
	//cout << "1ID: " << id << " " << x << " " << y << " " << d << endl;
	int tox = x, toy = y;
	
	tox += (d == 1);
	tox -= (d == 3);
	toy += (d == 2);
	toy -= (d == 4);
	
	if(tox == 0 || tox == n || toy == m || toy == 0)
		bor(tox, toy, d);

	if( a[tox][toy].size() || a[tox + 1][toy].size() )
	{
		if( can( x, y, d ) )
		{
		}
		else
		{
			tox += (d == 1);
			tox -= (d == 3);
			toy += (d == 2);
			toy -= (d == 4);
			
			if(tox == 0 || tox == n || toy == m || toy == 0)
				bor(tox, toy, d);
		}
		
		//cout << "2ID: " << id << " " << tox << " " << toy << " " << d << endl;
		
		if(tox == 0 || tox == n || toy == m || toy == 0)
			bor(tox, toy, d);
	}
	
	if(tox == 0 || tox == n || toy == m || toy == 0)
		bor(tox, toy, d);
	
	//puts("OK");
	v[id].fr.fr = tox;
	v[id].fr.sc = toy;
	b[tox][toy].pb(d);
	return;
}

void start(int time)
{
	for(time; time < t; time++)
	{
		for(int i = 0; i < k; i++)
		{
			move( v[i].fr.fr, v[i].fr.sc, v[i].sc.fr, i );
		}
		
		for(int i = 0; i <= n; i++)
		{
			for(int j = 0; j <= m; j++)
			{
				a[j][i] = b[j][i];
			}
		}
	}
}

main()
{
	cin >> n >> m >> k >> t;
	for(int i = 1; i <= k; i++)
	{
		int x, y, d;
		cin >> x >> y >> d;
		
		a[x][y].pb(d);
		b[x][y].pb(d);
		v.pb( mk( mk( x, y ), mk( d, i ) ) );
	}
	
	sort(v.begin(), v.end());
	start(0);
	
	vector < pair < pair < int, int >, pair < int, int > > > res;
	for(auto i : v)
	{
		res.pb( mk( mk( i.sc.sc, i.sc.fr ), mk( i.fr.fr, i.fr.sc ) ) );
	}
	
	sort(res.begin(), res.end());
	for(auto i : res)
	{
		cout << i.sc.fr << " " << i.sc.sc << " " << i.fr.sc << endl;
	}
}

Compilation message

ants.cpp: In function 'void start(int)':
ants.cpp:135:10: warning: statement has no effect [-Wunused-value]
  for(time; time < t; time++)
          ^
ants.cpp: At global scope:
ants.cpp:152:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 888 KB Output is correct
2 Correct 2 ms 988 KB Output is correct
3 Incorrect 2 ms 988 KB Output isn't correct
4 Halted 0 ms 0 KB -