Submission #34751028


Source Code Expand

    #include <bits/stdc++.h>

    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    // #pragma GCC target("popcnt")

using namespace std;
using namespace __gnu_pbds;

    template <typename t>
using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;

    // #pragma gcc optimize("ofast")
    // #pragma gcc target("avx,avx2,fma")


    #define int long long

    #define all(x) (x).begin(), (x).end()


    #define pb push_back
    #define endl '\n'
    #define fi first
    #define se second

    // const int mod = 1e9 + 7;

const int mod=998'244'353;


const long long INF = 2e18 + 10;
    // const int INF=1e9+10;

    #define readv(x, n)   \
vector<int> x(n); \
for (auto &i : x) \
    cin >> i;



    template <typename t>
using v = vector<t>;

    template <typename t>
using vv = vector<vector<t>>;

    template <typename t>
using vvv = vector<vector<vector<t>>>;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;

typedef pair<int, int> pii;



int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); }
int mult_identity(int a) { return 1; }



const double pi = acosl(-1);



auto power(auto a, auto b, const int in_mod)
{

    auto prod = mult_identity(a);
    auto mult = a % in_mod;
    while (b != 0)
    {
        if (b % 2)
        {
            prod = multiply(prod, mult, in_mod);
        }
        if(b/2)
            mult = multiply(mult, mult, in_mod);
        b /= 2;
    }
    return prod;
}
auto mod_inv(auto q, const int in_mod)
{
    return power(q, in_mod - 2, in_mod);
}


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



#define stp cout << fixed << setprecision(20);
#define trie asdfads

const int K = 26;

struct Vertex {
    int next[K];
    bool leaf = false;
    int dc = 0;

    Vertex() {
        fill(begin(next), end(next), -1);
    }
};

vector<Vertex> trie(1);


pair<int,int> add_string(string const& s) {
    int v = 0;

    int cnt = 0;

    for (char ch : s) {
        int c = ch - 'a';
        if (trie[v].next[c] == -1) {
            trie[v].next[c] = trie.size();
            trie.emplace_back();
        }
        if(trie[v].leaf)
            cnt++;
        v = trie[v].next[c];
    }
    trie[v].leaf = true;
    return {cnt,trie[v].dc  - 1};
}

void calc_trie()
{
    for(int i = trie.size() - 1;i>=0;i--)
    {
        if(trie[i].leaf)
            trie[i].dc ++;

        for(int j= 0;j<K;j++)
        {
            if(trie[i].next[j] != -1)
            {
                trie[i].dc += trie[trie[i].next[j]].dc;
            }
        }
    }

} 

void solv()
{
    int n;
    cin>>n;

    vector<string> s(n);

    for(int i = 0;i<n;i++)
    {
        cin>>s[i];
        add_string(s[i]);
    }
    calc_trie();

    for(int i = 0;i<n;i++)
    {
        pair<int,int> cnt = add_string(s[i]);

        int strict_less = cnt.fi  + 1;
        int strict_greater = cnt.se;


        int free = ( n - strict_less - strict_greater ) * mod_inv(2,mod) %mod;
        cout<<(free + strict_less)%mod<<endl;

    }




}

void solve()
{

    int t = 1;
        // cin>>t;
    while(t--)
    {
        solv();
    }
}




signed main()
{



    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cerr.tie(NULL);

    auto clk = clock();
        // -------------------------------------Code starts here---------------------------------------------------------------------

    signed t = 1;
        // cin >> t;

    for (signed test = 1; test <= t; test++)
    {
            // cout<<"Case #"<<test<<": ";

        solve();
    }

        // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;

        #ifndef ONLINE_JUDGE
    cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
        #endif
    return 0;
}

Submission Info

Submission Time
Task G - Random Student ID
User Wernier
Language C++ (GCC 9.2.1)
Score 600
Code Size 4300 Byte
Status AC
Exec Time 182 ms
Memory 120540 KiB

Compile Error

./Main.cpp: In function ‘long long int mult_identity(long long int)’:
./Main.cpp:63:23: warning: unused parameter ‘a’ [-Wunused-parameter]
   63 | int mult_identity(int a) { return 1; }
      |                       ^
./Main.cpp: At global scope:
./Main.cpp:71:12: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
   71 | auto power(auto a, auto b, const int in_mod)
      |            ^~~~
./Main.cpp:71:20: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
   71 | auto power(auto a, auto b, const int in_mod)
      |                    ^~~~
./Main.cpp:88:14: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
   88 | auto mod_inv(auto q, const int in_mod)
      |              ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 28
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 12 ms 4092 KiB
001.txt AC 12 ms 4280 KiB
002.txt AC 2 ms 3460 KiB
003.txt AC 118 ms 35992 KiB
004.txt AC 106 ms 36096 KiB
005.txt AC 174 ms 118384 KiB
006.txt AC 180 ms 118160 KiB
007.txt AC 177 ms 118220 KiB
008.txt AC 176 ms 118276 KiB
009.txt AC 13 ms 5376 KiB
010.txt AC 14 ms 5252 KiB
011.txt AC 14 ms 5248 KiB
012.txt AC 112 ms 34264 KiB
013.txt AC 101 ms 61244 KiB
014.txt AC 97 ms 60796 KiB
015.txt AC 94 ms 60784 KiB
016.txt AC 139 ms 64244 KiB
017.txt AC 137 ms 64144 KiB
018.txt AC 141 ms 63840 KiB
019.txt AC 141 ms 63864 KiB
020.txt AC 144 ms 63512 KiB
021.txt AC 142 ms 63520 KiB
022.txt AC 144 ms 63388 KiB
023.txt AC 146 ms 63336 KiB
024.txt AC 179 ms 120484 KiB
025.txt AC 182 ms 120540 KiB
example0.txt AC 3 ms 3452 KiB
example1.txt AC 3 ms 3508 KiB