QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789697#9564. Hey, Have You Seen My Kangaroo?little_rainWA 372ms12892kbC++143.0kb2024-11-27 21:29:322024-11-27 21:29:38

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 21:29:38]
  • 评测
  • 测评结果:WA
  • 用时:372ms
  • 内存:12892kb
  • [2024-11-27 21:29:32]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int i=l, _=r; i<=_; i++)
#define per(i, l, r) for (int i=l, _=r; i>=_; i--)
using namespace std;
ll read()
{
    ll s=0, t=1; char ch=getchar();
    for (; ch<'0'||ch>'9'; ch=getchar()) if (ch=='-') t=0;
    for (; ch>='0'&&ch<='9'; ch=getchar()) s=s*10+ch-'0';
    return t?s:-s;
}

const int M=2e5+5, dx[4]={-1, 1, 0, 0}, dy[4]={0, 0, -1, 1};
int dr[100];
int n, m, K;

bool a[M];
struct crd{
    int x, y;
    int nm(){return (x-1)*m+y;}
} p[M], tnp[M];
crd go(crd p, int dir){
    int nx=p.x+dx[dir], ny=p.y+dy[dir];
    if (!nx||!ny||nx>n||ny>m||!a[(crd){nx, ny}.nm()]) return p;
    return (crd){nx, ny};
}
int nm(int x, int y) {return (x-1)*m+y;}
struct que{
    crd x; int tn;
} q[M];
int cnt[M], deg[M], tdeg[M], ans[M];
char op[M], ch[M];
void chgp(crd *p, int dir) {
    rep(x, 1, n) rep(y, 1, m) if (a[nm(x, y)])
        p[nm(x, y)]=go(p[nm(x, y)], dir);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    dr['U']=0; dr['D']=1; dr['L']=2; dr['R']=3;
    n=read(), m=read(), K=read();
    scanf("%s", op+1);
    rep(i, 1, n) {
        scanf("%s", ch+1);
        rep(j, 1, m) a[nm(i, j)]=ch[j]^48;
    }
    // rep(i, 1, n) rep(j, 1, m) printf("%d%c", a[nm(i, j)], " \n"[j==m]);
    // cerr<<go((crd){1, 1}, 1).x<<" "<<go((crd){1, 1}, 1).y;

    rep(i, 1, n) rep(j, 1, m) if (a[nm(i, j)]) p[nm(i, j)]=tnp[nm(i, j)]=(crd){i, j};
    rep(i, 1, K) chgp(tnp, dr[op[i]]);// init tnp
    rep(i, 1, n*m) if (a[i]) deg[tnp[i].nm()]++;// init deg
    // rep(i, 1, n) rep(j, 1, m) printf("(%d, %d)%c", tnp[nm(i, j)].x, tnp[nm(i, j)].y, " \n"[j==m]);
    memset(ans, 0x3f, sizeof(ans));

    rep(k, 0, K-1) {
        // printf("k=%d\n", k);
        // rep(i, 1, n) rep(j, 1, m) printf("(%d, %d)%c", p[nm(i, j)].x, p[nm(i, j)].y, " \n"[j==m]);
        memcpy(tdeg, deg, sizeof tdeg);
        memset(cnt, 0, sizeof(cnt));
        int l=1, r=0;
        int cur=0, ct=0;
        rep(i, 1, n*m) cnt[p[i].nm()]++;
        rep(i, 1, n) rep(j, 1, m) if (a[nm(i, j)]) {
            cur+=cnt[nm(i, j)]>0;
            if (!deg[nm(i, j)]) q[++r]={(crd){i, j}, 1};//, printf("push %d %d %d\n", i, j, 1);
        }
        while (l<=r) {
            if (q[l].tn!=ct) {
                ans[cur]=min(ans[cur], ct*K+k);
                ct++;
            }
            // printf("pop (%d, %d) %d\n", q[l].x.x, q[l].x.y, q[l].tn);
            crd x=q[l++].x;
            int num=tnp[x.nm()].nm();
            tdeg[num]--;// printf("%d %d %d\n", tnp[x.nm()].x, tnp[x.nm()].y, tdeg[num]);
            if (!tdeg[num]) q[++r]=(que){tnp[x.nm()], ct+1};//printf("push %d %d %d\n", p[x.nm()].x, p[x.nm()].y, ct+1);
            cnt[num=p[x.nm()].nm()]--;
            if (!cnt[num]) cur--;
        }
        ans[cur]=min(ans[cur], ct*K+k);
        chgp(p, dr[op[k+1]]);
    }
    rep(i, 1, n*m) ans[i]=min(ans[i], ans[i-1]);
    rep(i, 1, n*m) printf("%d\n", ans[i]>1e9?-1:ans[i]);
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10812kb

input:

3 3 6
ULDDRR
010
111
010

output:

-1
4
2
1
0
0
0
0
0

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 10964kb

input:

3 3 6
ULDDRR
010
111
011

output:

7
4
2
1
1
0
0
0
0

result:

ok 9 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 10992kb

input:

1 5 1
R
11111

output:

4
3
2
1
0

result:

ok 5 number(s): "4 3 2 1 0"

Test #4:

score: 0
Accepted
time: 372ms
memory: 12744kb

input:

1 200000 200
RDRLDRULURDLDRULLRULLRRULRULRDLLDLRUDDLRURLURLULDRUUURDLUDUDLLLLLURRDURLUDDRRLRRURUUDDLLDDUUUDUULRLRUDULRRUURUDDDDLULULLLLLLLLLLLUDURLURLRLLRRRURUURLUDULDUULRRLULLRUDRDRUUDDRUDRDLLDLURDDDURLUULDRRDLDD
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

3999923
3999865
3999864
3999740
3999729
3999728
3999727
3999726
3999725
3999724
3999723
3999665
3999664
3999540
3999529
3999528
3999527
3999526
3999525
3999524
3999523
3999465
3999464
3999340
3999329
3999328
3999327
3999326
3999325
3999324
3999323
3999265
3999264
3999140
3999129
3999128
3999127
3999...

result:

ok 200000 numbers

Test #5:

score: -100
Wrong Answer
time: 369ms
memory: 12892kb

input:

2 100000 200
UULDRDLURDLDDRDRDUULDLUUULLRURLUUDDDRURURLLRRUDLDDDUDDRRUUURDDULURURLRULLUDLULURUUDURLDRRRDULRDLRRLDUUUDDUUDUDRDRUDLDRRUDRDLDRDLDRRDLRRDRDLRRLUDUDRULLRRLDDLUDDULDRLLLDLURRDDULDDUDULLRRRUURLRRRLURDLRLU
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 16th numbers differ - expected: '384513', found: '-1'