Submission #491135

# Submission time Handle Problem Language Result Execution time Memory
491135 2021-11-30T16:00:52 Z Yazan_Alattar Parametriziran (COCI19_parametriziran) C++14
88 / 110
904 ms 65540 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

map <ll,ll> cnt[200][200];
ll n, m, ans;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        string s;
        cin >> s;
        ll mask = 0, tmp[200];
        memset(tmp, -1, sizeof tmp);
        for(int j = 0; j < m; ++j) if(s[j] != '?') mask |= (1 << j);
        for(int mask2 = 0; mask2 < (1 << m); ++mask2){
            if((mask & mask2) != mask2) continue;
            int cur = 0;
            for(ll j = 0, p = 1; j < m; ++j, p *= 26) if((mask2 >> j) & 1) cur += p * (s[j] - 'a');
            tmp[mask2] = cur;
        }
        for(int mask2 = 0; mask2 < (1 << m); ++mask2){
            int res = (mask & mask2);
            ans += cnt[mask2][res][tmp[res]];
        }
        for(int mask2 = 0; mask2 < (1 << m); ++mask2) if(tmp[mask2] != -1) ++cnt[mask][mask2][tmp[mask2]];
    }
    cout << ans << endl;
    return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2236 KB Output is correct
2 Correct 11 ms 2240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2240 KB Output is correct
2 Correct 22 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3064 KB Output is correct
2 Correct 19 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2844 KB Output is correct
2 Correct 38 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 11384 KB Output is correct
2 Correct 28 ms 2956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 463 ms 25260 KB Output is correct
2 Correct 30 ms 4008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 876 ms 45892 KB Output is correct
2 Correct 370 ms 21784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 904 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 814 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -