답안 #334574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334574 2020-12-09T12:49:59 Z doowey Parametriziran (COCI19_parametriziran) C++14
110 / 110
227 ms 15212 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int M = 6;
const int AL = 27;
const int N = 50005;

vector<int> ind[1<<M];
int f[M];
string s[N];
int vl[N][1<<M];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    f[0]=1;
    for(int i = 1; i < M ; i ++) {
        f[i]=(f[i-1]*AL);
    }
    int que;
    int sln;
    for(int i = 0 ; i < n; i ++ ){
        cin >> s[i];
        que = 0;
        for(int j = 0 ; j < m ; j ++ ){
            if(s[i][j] == '?') que |= (1 << j);
        }
        ind[que].push_back(i);
        for(int mm = 0 ; mm < (1 << m); mm ++ ){
            if((mm & que) != que) continue;
            sln = 0;
            for(int j = 0 ; j < m ; j ++ ){
                if((mm & (1 << j))) continue;
                sln += f[j] * 1ll * (s[i][j] - 'a' + 1);
            }
            vl[i][mm]=sln;
        }
    }
    ll soln = 0;
    vector<int> ay, by;
    int mask;
    int jj,c1,c2;
    for(int p = 0 ; p < (1 << m); p ++ ){
        for(int q = p + 1 ; q < (1 << m) ; q ++ ){
            if(ind[p].empty() || ind[q].empty()) continue;
            mask = (p | q);
            ay.clear();
            by.clear();
            for(auto x : ind[p]){
                ay.push_back(vl[x][mask]);
            }
            for(auto x : ind[q]){
                by.push_back(vl[x][mask]);
            }
            sort(ay.begin(), ay.end());
            sort(by.begin(), by.end());
            jj = 0;
            c1 = 0;

            for(int i = 0 ; i < ay.size(); i ++ ){
                c1 ++ ;
                if(i + 1 == ay.size() || ay[i] != ay[i + 1]){
                    c2 = 0;
                    while(jj < by.size() && by[jj] <= ay[i]){
                        if(by[jj] == ay[i]){
                            c2 ++ ;
                        }
                        jj ++ ;
                    }
                    soln += c1 * 1ll * c2;
                    c1 = 0;
                }
            }
        }
        ay.clear();
        for(auto x : ind[p]){
            ay.push_back(vl[x][p]);
        }
        sort(ay.begin(), ay.end());
        c1 = 0;
        for(int i = 0 ; i < ay.size(); i ++ ){
            soln += c1;
            c1 ++ ;
            if(i + 1 == ay.size() || ay[i] != ay[i + 1]){
                c1 = 0;
            }
        }
    }
    cout << soln << "\n";
    return 0;
}

Compilation message

parametriziran.cpp: In function 'int main()':
parametriziran.cpp:70:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int i = 0 ; i < ay.size(); i ++ ){
      |                             ~~^~~~~~~~~~~
parametriziran.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |                 if(i + 1 == ay.size() || ay[i] != ay[i + 1]){
      |                    ~~~~~~^~~~~~~~~~~~
parametriziran.cpp:74:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |                     while(jj < by.size() && by[jj] <= ay[i]){
      |                           ~~~^~~~~~~~~~~
parametriziran.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(int i = 0 ; i < ay.size(); i ++ ){
      |                         ~~^~~~~~~~~~~
parametriziran.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             if(i + 1 == ay.size() || ay[i] != ay[i + 1]){
      |                ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 9964 KB Output is correct
2 Correct 13 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12268 KB Output is correct
2 Correct 21 ms 15208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 9580 KB Output is correct
2 Correct 18 ms 9708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 14572 KB Output is correct
2 Correct 22 ms 7660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 14700 KB Output is correct
2 Correct 36 ms 12908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 10988 KB Output is correct
2 Correct 48 ms 9848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 13036 KB Output is correct
2 Correct 84 ms 14060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 10476 KB Output is correct
2 Correct 56 ms 10604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 14956 KB Output is correct
2 Correct 169 ms 15212 KB Output is correct