ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1251. Cemetery Manager

To anyone got 'time limted': could you show your program?
Posted by Lin 22 Mar 2003 19:04
<P><P><P>: could you show your TL program?
Posted by Lin 24 Mar 2003 20:14
>
I got TLE. I did the same thing, but in a faster way and I got WA (maybe it passed the tests this program got TLE and still got WA)
Posted by Scythe (Berinde Radu) 24 Mar 2003 20:17
#include <stdio.h>
#include <stdlib.h>

#define T1 1000
#define T2 100
#define NVEC 8

#define INF 66666
int Lasttime;
int Clients;
int Empty, Canmove;
#define time(i, j) (Time - Lasttime[Cl[i][j]])

int vi = {0, 0, -1, 1, 1, -1, 1, -1};
int vj = {1, -1, 0 ,0, -1, 1, 1, -1};
#define ni (i + vi[v])
#define nj (j + vj[v])

int Cl, N, M;
int Time;

{
int i, j, x, v, fnd, Res = 0;
char a;
scanf("%d %d", &N, &M);
Lasttime = -INF;
while (scanf("%d %c", &Time, &a) == 2)
{
if (a == 'v')
{
scanf("%d", &x);
if (!Empty[x]) Lasttime[x] = Time;
continue;
}
for (i = 1; i <= N; i++)
for (j = 1; j <= M; j++)
if (Cl[i][j] && (!Empty[Cl[i][j]] || !Canmove[Cl[i][j]]))
{
if (time(i, j) > T1) Empty[Cl[i][j]] = 1;
for (v = 0; v < NVEC; v++)
if (ni > 0 && nj > 0 && ni <= N && nj <= M &&
Cl[ni][nj] && time(ni, nj) <= T2)
break;
if (v == NVEC) Canmove[Cl[i][j]] = 1;
}
Lasttime[++Clients] = Time;
for (fnd = 0, i = 1; !fnd && i <= N; i++)
for (j = 1; !fnd && j <= M; j++)
if (Cl[i][j] == 0 || (Empty[Cl[i][j]] && Canmove[Cl[i]
[j]]))
Cl[i][j] = Clients, fnd = 1;

if (!fnd) Res++;
}
printf("%d\n", Res);
}

int main()
{