# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90293 | YottaByte | 움직이는 개미 (IZhO12_ants) | C++14 | 2 ms | 988 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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 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])
{
//cout << x << " " << y << " " << i << endl;
if( i == revd )
{
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 move( int x, int y, int &d, int id )
{
b[x][y].pop_back();
//cout << a[4][1].size() << endl;
//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( 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);
}
//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);
v[id].fr.fr = tox;
v[id].fr.sc = toy;
b[tox][toy].pb(d);
//cout << "2ID: " << id << " " << tox << " " << toy << " " << d << endl;
return;
}
void out()
{
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
if(a[i][j].size()) cout << '*';
else cout << 0;
}
puts("");
}
}
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 );
}
//ok;
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
a[i][j].clear();
a[i][j] = b[i][j];
}
}
//out();
}
}
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 ) ) );
}
//out();
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;
}
}
/*
4 4 2 3
1 1 1
3 3 4
4 4 2 4
1 1 1
3 3 4
4 4 2 2
1 1 1
3 1 3
4 4 2 2
2 1 1
3 1 3
4 2 2 3
2 1 1
3 1 1
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |