답안 #867073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867073 2023-10-27T16:28:36 Z HoriaHaivas Parametriziran (COCI19_parametriziran) C++14
99 / 110
921 ms 65536 KB
/*
    "care a facut teste cu Lattice reduction attack e ciudat"
    "linistiti va putin"
    - 2023 -
*/
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#warning ai grija la ? ca l ai transformat in {
#pragma GCC optimize("Ofast")

using namespace std;

const int mod=1e9+9;
const int base=29;

string s[50001];
unordered_map<int,unsigned short int> hashcount[(1<<6)];

int main()
{
    ifstream fin(".in");
    ofstream fout(".out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i,j,n,m,ans,mask,hashbuild,mask2;
    bool ok;
    cin >> n >> m;
    for (j=1; j<=n; j++)
    {
        cin >> s[j];
        for (i=0; i<s[j].size(); i++)
        {
            if (s[j][i]=='?')
                s[j][i]='{';///urmatorul caracter dupa z
        }
        for (mask=1; mask<(1<<(m)); mask++)
        {
            hashbuild=0;
            for (i=0; i<s[j].size(); i++)
            {
                if (mask&(1<<i))
                    hashbuild=((hashbuild*base)%mod+(s[j][i]-'a'+1))%mod;
            }
            hashcount[mask][hashbuild]++;
        }
    }
    ans=0;
    for (j=1; j<=n; j++)
    {
        mask=0;
        for (i=0; i<s[j].size(); i++)
        {
            if (s[j][i]!='{')
            {
                mask=mask|(1<<i);
            }
        }
        if (mask!=0)
        {
            for (mask2=0; mask2<=mask; mask2++)
            {
                ok=true;
                for (i=0; i<s[j].size() && ok; i++)
                {
                    if ((mask2&(1<<i)) && !(mask&(1<<i)))
                        ok=false;
                }
                if (ok)
                {
                    hashbuild=0;
                    for (i=0; i<s[j].size(); i++)
                    {
                        if (mask&(1<<i))
                        {
                            if (mask2&(1<<i))
                                hashbuild=((hashbuild*base)%mod+('{'-'a'+1))%mod;
                            else
                                hashbuild=((hashbuild*base)%mod+(s[j][i]-'a'+1))%mod;
                        }
                    }
                    ans+=hashcount[mask][hashbuild];
                }
            }
        }
        else
        {
            ans+=n;
        }
    }
    cout << (ans-n)/2;
    return 0;
}

Compilation message

parametriziran.cpp:9:2: warning: #warning ai grija la ? ca l ai transformat in { [-Wcpp]
    9 | #warning ai grija la ? ca l ai transformat in {
      |  ^~~~~~~
parametriziran.cpp: In function 'int main()':
parametriziran.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (i=0; i<s[j].size(); i++)
      |                   ~^~~~~~~~~~~~
parametriziran.cpp:41:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for (i=0; i<s[j].size(); i++)
      |                       ~^~~~~~~~~~~~
parametriziran.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (i=0; i<s[j].size(); i++)
      |                   ~^~~~~~~~~~~~
parametriziran.cpp:65:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |                 for (i=0; i<s[j].size() && ok; i++)
      |                           ~^~~~~~~~~~~~
parametriziran.cpp:73:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                     for (i=0; i<s[j].size(); i++)
      |                               ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1880 KB Output is correct
2 Correct 5 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2064 KB Output is correct
2 Correct 8 ms 2064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2652 KB Output is correct
2 Correct 10 ms 2076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2396 KB Output is correct
2 Correct 21 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 8032 KB Output is correct
2 Correct 21 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 17460 KB Output is correct
2 Correct 37 ms 3080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 31692 KB Output is correct
2 Correct 148 ms 15824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 60372 KB Output is correct
2 Correct 90 ms 4980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 904 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -