Submission #1040503

#TimeUsernameProblemLanguageResultExecution timeMemory
1040503antonCubeword (CEOI19_cubeword)C++17
0 / 100
1177 ms177064 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> const int MOD = 998244353LL; const int MAX_N = 40LL; int nbP[MAX_N][MAX_N]; int RES = 0; vector<pii> cube_edges = { {0, 1}, {1, 2}, {2, 3}, {3, 0}, {4, 5}, {5, 6}, {6, 7}, {7, 4}, {0, 4}, {1, 5}, {2, 6}, {3, 7}, }; bool is_palindrome(string s){ bool ok = true; for(int i = 0; i<(s.size()+1)/2; i++){ ok &= (s[i] == s[s.size()-i-1]); } return ok; } vector<vector<int>> iterate_all(int nbSteps, int maxC){ vector<int> cur = vector<int>(nbSteps, 0); vector<vector<int>> res; bool ok = true; while(ok){ cur.back()++; for(int i = nbSteps-1; i>0; i--){ if(cur[i]>=maxC){ cur[i-1]++; cur[i] = 0; } } if(cur[0] >=maxC){ ok = false; cur[0] = 0; } res.push_back(cur); } return res; } signed main(){ int N; cin>>N; vector<string> words; for(int i = 0; i<N; i++){ string s; cin>>s; words.push_back(s); } for(int len = 3; len<=10; len++){ fill(&nbP[0][0], &nbP[MAX_N][0], 0); int max_c= 2; for(auto e: words){ if(e.size() == len){ int a= e[0]-'a'; int b= e.back()-'a'; max_c = max(max_c, a+1); max_c= max(max_c, b+1); if(is_palindrome(e)){ nbP[a][b]++; } else{ nbP[a][b]++; nbP[b][a]++; } } } for(auto list: iterate_all(8, max_c)){ int nb_cur = 1; for(auto edge: cube_edges){ nb_cur = (nb_cur * nbP[list[edge.first]][list[edge.second]])%MOD; } RES += nb_cur; } } cout<<RES<<endl; }

Compilation message (stderr)

cubeword.cpp: In function 'bool is_palindrome(std::string)':
cubeword.cpp:30:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i<(s.size()+1)/2; i++){
      |                    ~^~~~~~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:76:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   76 |             if(e.size() == len){
      |                ~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...