QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95761#5576. Advertising ICPCtriplem5ds#WA 12ms13776kbC++203.9kb2023-04-11 20:29:562023-04-11 20:29:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 20:29:59]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:13776kb
  • [2023-04-11 20:29:56]
  • 提交

answer

///Enta etfsh5t nseet el rank

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
//#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ull = unsigned long long;
using uint = uint32_t;
using ii = pair<int, int>;

const int N = 1e5 + 20, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);

const long double EPS = 1e-9;

char grid[8][8];
int dp[8][8][6561][3];
int n, m;
int pwr3[8];
int maskBits[6561][8];

int get(char c) {
    if (c == 'I')
        return 0;
    if (c == 'C')
        return 1;
    return 2;
}

int solve(int row, int col, int mask, int prv) {
    if (row == n)
        return 1;
    if (col == m) {
        return solve(row + 1, 0, mask, 0);
    }
    int &ret = dp[row][col][mask][prv];
    if (~ret)
        return ret;
    ret = 0;
    if (row == 0) {
        if (grid[row][col] == '?') {
            ret = (ret + solve(row, col + 1, mask, 0)) % MOD;
            ret = (ret + solve(row, col + 1, mask + pwr3[col], 0)) % MOD;
            ret = (ret + solve(row, col + 1, mask + pwr3[col] * 2, 0)) % MOD;
        } else {
            ret = (ret + solve(row, col + 1, mask + pwr3[col] * get(grid[row][col]), 0));
        }
    } else {
        if (col == 0) {
            mask -= maskBits[mask][col] * pwr3[col];
            if (grid[row][col] == '?') {
                ret = (ret + solve(row, col + 1, mask, maskBits[mask][col])) % MOD;
                ret = (ret + solve(row, col + 1, mask + pwr3[col], maskBits[mask][col])) % MOD;
                ret = (ret + solve(row, col + 1, mask + pwr3[col] * 2, maskBits[mask][col])) % MOD;
            } else {
                ret = (ret + solve(row, col + 1, mask + pwr3[col] * get(grid[row][col]), maskBits[mask][col]));
            }
        } else {
            bool cantC = (prv == 0) && (maskBits[mask][col] == 1) && (maskBits[mask][col - 1] == 2);
            mask -= maskBits[mask][col] * pwr3[col];
            if (grid[row][col] == '?') {
                ret = (ret + solve(row, col + 1, mask, maskBits[mask][col])) % MOD;
                if (!cantC)
                    ret = (ret + solve(row, col + 1, mask + pwr3[col], maskBits[mask][col])) % MOD;
                ret = (ret + solve(row, col + 1, mask + pwr3[col] * 2, maskBits[mask][col])) % MOD;
            } else if (!cantC || grid[row][col] != 'C') {
                ret = (ret + solve(row, col + 1, mask + pwr3[col] * get(grid[row][col]), maskBits[mask][col]));
            }
        }
    }
    return ret;
}

void doWork() {

    pwr3[0] = 1;
    f(i, 1, 8)pwr3[i] = pwr3[i - 1] * 3;

    cin >> n >> m;
    int tot = 1;
    f(i, 0, n) {
        f(j, 0, m) {
            cin >> grid[i][j];
            if (grid[i][j] == '?')
                tot = tot * 3 % MOD;
        }
    }
    for (int i = 0; i < 6561; i++) {
        for (int j = 0, cur = i; j < 8; j++, cur /= 3) {
            maskBits[i][j] = cur % 3;
        }
    }
    memset(dp, -1, sizeof dp);
    cout << (tot + MOD - solve(0, 0, 0, 0)) % MOD << '\n';

}

int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE
    int t = 1;
//    cin >> t;
    while (t--)
        doWork();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13652kb

input:

3 3
???
?I?
???

output:

243

result:

ok single line: '243'

Test #2:

score: 0
Accepted
time: 5ms
memory: 13772kb

input:

2 2
IC
PC

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 13776kb

input:

8 8
????????
????????
????????
????????
????????
????????
????????
????????

output:

682554315

result:

wrong answer 1st lines differ - expected: '776529021', found: '682554315'