QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790275#9802. Light Up the GridMYdinosaurTL 204ms4672kbC++143.1kb2024-11-28 09:33:562024-11-29 22:57:41

Judging History

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

  • [2024-11-29 22:57:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:204ms
  • 内存:4672kb
  • [2024-11-28 09:33:58]
  • 评测
  • 测评结果:0
  • 用时:200ms
  • 内存:4668kb
  • [2024-11-28 09:33:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pa;
const int N = 1 << 17;
int cost[5];
ll a[20];
int m;
int T;
ll sum = 0;
ll ans = 1e9 + 10;
ll f[20][20];
int vis[20];
ll pat[N];
int p1[5] = {0, 1, 2, 4, 8};
int p2[3] = {0, 3, 12};
int p3[3] = {0, 5, 10};
int p4[2] = {0, 15};
struct node{
    int x, y, z;
}b[1001];
int fa[20];

inline void read(int &x)
{
    x = 0;
    int w = 1; char c = getchar();
    while (!isdigit(c)) {if (c == '-') w = -1; c = getchar();} 
    while (isdigit(c)) {x = x * 10 + (c ^ 48); c = getchar();}
    x = x * w;
}

bool cmp(node f1, node f2)
{
    return f1.z < f2.z;
}


void dg(int dep, int x, ll g, ll gh)
{
    if (g >= ans) return;
    if (dep == 16)
    {
        return;
    }
    for (int i = 0; i <= 15; i++)
    {
        if (vis[i]) continue;  
        int fg = gh | (1 << i);  
        // if (i == 15 && x == 15 )cout << i << " " << x << " " << f[i][x] << " " << g << endl;
        if (g + f[i][x] > pat[fg]) continue;
      
        pat[fg] = g + f[i][x];
        vis[i] = 1;
        dg(dep + 1, i, g + f[i][x], fg);
        vis[i] = 0;
    }
}

void prepare()
{
    memset(pat, 0x3f3f3f, sizeof(pat));
    memset(f, 0x3f3f3f, sizeof(f));
    read(T); 
    int h = 1e7 + 10;
    for (int i = 1; i <= 4; i++) 
    {
        read(cost[i]);
        h = min(h, cost[i]);
    } 

    for (int i = 0; i <= 15; i++)
    {
        f[i][i] = 0;
        for (int j = 1; j <= 4; j++)
        {
            int x = i ^ p1[j];
            f[i][x] = cost[1];
        }
        for (int j = 1; j <= 2; j++)
        {
            int x = i ^ p2[j];
            f[i][x] = cost[2];
        }
        for (int j = 1; j <= 2; j++)
        {
            int x = i ^ p3[j];
            f[i][x] = cost[3];
        }
        int x = i ^ 15;
        f[i][x] = cost[4];
    }   
    for (int k = 0; k <= 15; k++)
    {
        for (int i = 0; i <= 15; i++)
        {
            for (int j = 0; j <= 15; j++)
            {
                f[i][j] = min(f[i][k] + f[k][j], f[i][j]);
            }
        }
    }
    f[15][15] = 2 * h;        
    dg(0, 15, 0, 0);
}

int main()
{
    // freopen("1.out","w",stdout);
    prepare();
    // cout << T << "    " << f[15][15] << endl;
    while (T > 0)
    {
        T--;
        // int m;
        int tot = 0;
        read(m);
        int p = 0;
        ll sum = 0;
        // cout << m << endl;
        int jl = 0;
        for (int k = 1; k <= m; k++)
        {
            vis[k] = 0;
            ll t = 1;
            a[k] = 0;
            for (int i = 1; i <= 2; i++)
            {
                for (int j = 1; j <= 2; j++)
                {
                    char ch;
                    cin >> ch;
                    if (ch == '1') a[k] += t;
                    t = t * 2;
                }
            }    
            jl |= 1 << a[k];   
        }
        sum = pat[jl];
        // cout << jl << endl;
        cout << sum << endl;
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 204ms
memory: 4672kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: -100
Time Limit Exceeded

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:


result: