QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541303#7900. Gifts from KnowledgexuemanRE 16ms60112kbC++175.4kb2024-08-31 19:07:072024-08-31 19:07:08

Judging History

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

  • [2024-08-31 19:07:08]
  • 评测
  • 测评结果:RE
  • 用时:16ms
  • 内存:60112kb
  • [2024-08-31 19:07:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 1000 + 10;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

ll qpow(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

string s[maxn];
int vis[maxn];
vector<string> pos[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;

    while (T--)
    {
        int n, m;
        cin >> n >> m;
        int cur = 0, ok = 1;

        map<string, vector<int>> mp;
        for (int i = 1; i <= n; i++)
        {
            cin >> s[i];
            s[i] = ' ' + s[i];
            auto &v = mp[s[i]];
            
            if (!v.empty())
            {
                    pos[v.back()].push_back(s[i]);
                    continue;
            }

            for (int j = 0; j <= m; j++)
                vis[j] = 0;

            for (int j = 1; j <= m; j++)
            {
                if (s[i][j] == '1')
                {
                    // if (i == 3)
                    // cout << j;
                    if (!vis[j])
                        v.push_back(j), vis[j] = 1;
                    // if (i == 3)
                    // cout << m - j + 1 << ' ' << vis[m - j + 1] << endl;
                    if (!vis[m - j + 1])
                        v.push_back(m - j + 1), vis[m - j + 1] = 1;
                    // pos[m - j + 1].push_back(s[i]);
                }
            }
            if (!v.empty())
            {
                sort(v.begin(), v.end(), greater<int>());

                // if (i == 3)
                // {
                //     for (auto it : v)
                //         cout << it << ' ';
                // }
                // cout << v.back() << endl;

                pos[v.back()].push_back(s[i]);
            }
            else 
                cur++;
        }

        for (int i = 1; i <= m; i++)
        {
            if (pos[i].size() > 1)
            {

                // cout << i;
                auto x = pos[i].back();
                pos[i].pop_back();
                // mp.erase(x);
                for (auto y : pos[i])
                {
                    bool flag = 0;
                    // cout << x << ' ' << y << ' ';
                    for (int j = 1; j <= m; j++)
                    {
                        if (x[j] == '1' && y[j] == '1')
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag)
                    {
                        reverse(y.begin() + 1, y.end());
                        for (int j = 1; j <= m; j++)
                        {
                            if (x[j] == '1' && y[j] == '1')
                            {
                                ok = 0;
                                goto end;
                            }
                            x[j] = max(x[j], y[j]);
                        }
                    }
                    else
                    {
                        for (int j = 1; j <= m; j++)
                        {
                            if (x[j] == '1' && y[j] == '1')
                            {
                                ok = 0;
                                                            goto end;
                            }
                            x[j] = max(x[j], y[j]);
                        }
                        // cout << x;
                    }
                    // mp.erase(y);
                }

                // cout << x << endl;
                for (int j = i + 1; j <= m; j++)
                {
                    vis[j] = 0;
                }

                mp[x].clear();
    
                for (int j = i + 1; j <= m; j++)
                {
                    if (x[j] == '1')
                    {
                        if (!vis[j])
                            mp[x].push_back(j), vis[j] = 1;
                        if (m - j + 1 >= i + 1 && !vis[m - j + 1])
                            mp[x].push_back(m - j + 1), vis[m - j + 1] = 1;
                    }
                }

                // for (auto it : mp[x])
                // cout << it << ' ';
                if (!mp[x].empty())
                {
                    sort(mp[x].begin(), mp[x].end(), greater<int>());
                    pos[mp[x].back()].push_back(x);
                }
            }
            else if (pos[i].size() == 1)
            {
                // cout << i << '|';
                auto x = pos[i].back();
                pos[i].pop_back();
                auto &v = mp[x];
                v.pop_back();

                // for (auto i : v)
                //     cout << i << ' ';
                // cout << endl;

                if (v.empty())
                    cur++;
                else
                {
                    pos[v.back()].push_back(x);
                }
            }
        }
    end:
        if (!ok)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << qpow(2, cur) << endl;
        }

        for (int i = 0; i <= n; i++)
            pos[i].clear();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 60104kb

input:

3
3 5
01100
10001
00010
2 1
1
1
2 3
001
001

output:

4
0
2

result:

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

Test #2:

score: 0
Accepted
time: 16ms
memory: 60112kb

input:

15613
10 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
15 8
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
1 5
00000
5 9
000000000
000000000
0000...

output:

1024
32768
2
32
32768
128
32
16
16
2
16384
16384
128
128
32768
8192
128
64
16384
2
4
2
4096
16
4096
1024
32768
32768
16384
8
128
2
16
4096
8192
32768
8192
8192
16
16384
16384
256
128
8
256
8
4096
512
2
4
32
32
2
64
512
1024
32768
32768
2
64
16384
16
8192
16
256
16
64
8192
8192
64
1024
2
32768
2
4
51...

result:

ok 15613 numbers

Test #3:

score: -100
Runtime Error

input:

15759
9 6
000000
000000
000000
000000
000000
000000
000000
000000
000000
5 15
010000000000000
000000000000000
000000000000000
000100000000000
000100000000000
14 12
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000...

output:


result: