QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#840554#9802. Light Up the Gridfrankly6WA 37ms13168kbC++172.3kb2025-01-02 19:59:312025-01-02 19:59:33

Judging History

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

  • [2025-01-02 19:59:33]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:13168kb
  • [2025-01-02 19:59:31]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
const int MX=67000;
const int inf=0x3fffffff;

int T, N, M, a[4];
int head[MX], dis[MX], cnt=0;
bool vis[MX];
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
struct edge{int nxt, to, c;}e[200*MX];
inline void ae(int u, int v, int c)
{
    if(u==0||v==0) cout << "u=" << u << ", v=" << v << ", c=" << c << '\n';
    e[++cnt].to=v; e[cnt].nxt=head[u]; head[u]=cnt; e[cnt].c=c;
}
struct node
{
    int x, d;
    bool operator < (const node &a)const {return d>a.d;}
};
priority_queue<node> q;
void dij(int s)
{
    q.push({s,0}); dis[s]=0;
    while(!q.empty())
    {
        auto [x,d]=q.top(); q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=head[x];i;i=e[i].nxt)
        {
            int y=e[i].to;
            if(dis[y]<=dis[x]+e[i].c) continue;
            dis[y]=dis[x]+e[i].c;
            q.push({y,dis[y]});
        }
    }
}
int main()
{
  
    T=read(); 
    for(int i=0;i<4;i++) a[i]=read();
    for(int i=0;i<=(1<<16);i++) dis[i]=inf;
    PII move[9]={{1,a[0]},{2,a[0]},{4,a[0]},{8,a[0]},{3,a[1]},{12,a[1]},{5,a[2]},{10,a[2]},{15,a[3]}};
    for(int i=0;i<(1<<16);i++) // 每位对应一种 grid
    {
        // cout << "i=" << i << '\n';
        for(int j=0;j<=8;j++)
        {
            int s=0;
            auto [pos,c]=move[j];
            for(int k=0;k<=15;k++) //每个 grid 在 move[j] 下变化
            {
                if((i&(1<<k))==0) continue;
                // if(i==2&&k==1) cout << "i=" << i << ", k=" << k << ", pos=" << pos << '\n';
                s|=(1<<(k^pos));
            }   
            s&=((1<<15)-1);
            ae(s,i,c);
        }
    }
    dij(0);
    while(T--)
    {
        M=read();
        int s=0;
        for(int i=1;i<=M;i++)
        {
            int now=0;
            string s1; cin >> s1;
            now+=(s1[0]=='1')*8+(s1[1]=='1')*4;
            string s2; cin >> s2;
            now+=(s2[0]=='1')*2+(s2[1]=='1')*1;
            s|=(1<<now);
        }
        // cout << "s=" << s << '\n';
        cout << dis[s] << '\n';
    }
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 37ms
memory: 13168kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

u=0, v=0, c=1000
u=0, v=0, c=1000
u=0, v=0, c=1000
u=0, v=0, c=1000
u=0, v=0, c=100
u=0, v=0, c=100
u=0, v=0, c=10
u=0, v=0, c=10
u=0, v=0, c=1
u=0, v=1, c=1
u=0, v=8, c=100
u=0, v=32, c=10
u=0, v=128, c=1000
u=0, v=1024, c=10
u=0, v=2048, c=1000
u=0, v=4096, c=100
u=0, v=8192, c=1000
u=0, v=16384, ...

result:

wrong output format Expected integer, but "u=0," found