Submission #360023

# Submission time Handle Problem Language Result Execution time Memory
360023 2021-01-27T12:10:51 Z mohamedsobhi777 Cubeword (CEOI19_cubeword) C++14
0 / 100
1100 ms 109360 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define vvi vector<vi>
#define vvii vector<vii>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define uni(_) unique(_)
#define lb lower_bound
#define ub upper_bound
#define si set<int>
#define ms multiset<int>
#define qi queue<int>
#define pq prioriry_queue<int>
#define mi map<int, int>
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)

using lll = __int128;
using ll = long long;
using ld = long double;

const int N = 1e5 + 7;
const ll mod = 998244353;
const ll inf = 2e18;

auto ra = [] {char *p = new char ; delete p ; return ll(p) ; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1));
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> os;

int n;

int id(char c)
{
       if (c >= 'a' && c <= 'z')
              return c - 'a';
       if (c >= 'A' && c <= 'Z')
              return 26 + c - 'A';
       return 52 + c - '0';
}

const int S = 6;

int freq[S][S], freq1[S][S][S][S], cont[S][S];
ll D[S][S][S];
ll ans;
vector<string> gbl[N];

vector<array<int, 3>> his;

void clear()
{
       for (auto u : his)
              D[u[0]][u[1]][u[2]] = 0;
       his.clear();
}
int vis[S][S][S];

void solve(int ix)
{
       int z = sz(gbl[ix]);
       inc(a, 0, S - 1) inc(b, 0, z - 1) inc(c, 0, z - 1) inc(d, 0, z - 1)
       {
              if (id(gbl[ix][b][0]) == a && id(gbl[ix][c][0]) == a && id(gbl[ix][d][0]) == a)
              {
                     int l1 = id(gbl[ix][b][sz(gbl[ix][b]) - 1]);
                     int l2 = id(gbl[ix][c][sz(gbl[ix][c]) - 1]);
                     int l3 = id(gbl[ix][d][sz(gbl[ix][d]) - 1]);
                     ++D[l1][l2][l3];
                     his.pb({l1, l2, l3});
              }
       }
       z = sz(his);
       for (int i = 0; i < z; ++i)
       {
              int a = his[i][0], b = his[i][1], c = his[i][2];
              if (vis[a][b][c] == ix)
                     continue;
              vis[a][b][c] = ix;
              for (int j = 0; j < S; ++j)
              {
                     ans += 1ll * D[a][b][c] * D[a][b][j] % mod * D[b][c][j] % mod * D[a][c][j] % mod;
                     ans %= mod;
              }
       }
}

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif

       cin >> n;
       vector<string> vec;
       for (int i = 0; i < n; ++i)
       {
              string st, ts;
              cin >> st;
              ts = st;
              reverse(all(ts));

              gbl[sz(st)].pb(ts), gbl[sz(st)].pb(st);
       }
       for (int i = 3; i <= 10; ++i)
       {
              sort(all(gbl[i]));
              gbl[i].erase(unique(all(gbl[i])), gbl[i].end());
              solve(i);
              clear();
       }
       cout << ans;
       return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1153 ms 109360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1153 ms 109360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1153 ms 109360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1153 ms 109360 KB Time limit exceeded
2 Halted 0 ms 0 KB -