Submission #223244

#TimeUsernameProblemLanguageResultExecution timeMemory
223244SomeoneUnknownTrener (COCI20_trener)C++14
110 / 110
151 ms11896 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<string, int> > *prv;
int nof(string sstr){
    int l = -1;
    int h = prv->size();
    while(h-1>l){
        int mid = (h+l)/2;
        pair<string, int> x = (*prv)[mid];
        if(x.first == sstr){
            return x.second;
        }else if(x.first < sstr){
            l = mid;
        }else{
            h = mid;
        }
    }
    return 0;
}
//C:\Users\user\Documents\trener.cpp|9|error: conversion from 'std::vector<std::pair<std::__cxx11::basic_string<char>, int> >*' to non-scalar type 'std::pair<std::__cxx11::basic_string<char>, int>' requested|
int main(){
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    prv = new vector<pair<string, int> >();
    for(int i = 0; i < k; i++){
        string ns;
        cin >> ns;
        prv->push_back(make_pair(ns, 1));
    }
    sort(prv->begin(), prv->end());
    vector<pair<string, int> > *cur3;
    cur3 = new vector<pair<string, int> >();
    cur3->push_back(prv->front());
    for(int j = 1; j < prv->size(); j++){
        if((*prv)[j].first == cur3->back().first){
            cur3->back().second += (*prv)[j].second;
            cur3->back().second %= 1000000007;
        }else{
            cur3->push_back((*prv)[j]);
        }
    }
    prv = cur3;
    for(int i = 1; i < n; i++){
        string ns;
        vector<pair<string, int> > *cur;
        cur = new vector<pair<string, int> >();
        for(int l = 0; l < k; l++){
            cin >> ns;
            char scrafter[i+1];
            scrafter[i] = '\0';
            for(int j = 0; j < i; j++){
                scrafter[j] = ns[j];
            }
            string fs, ss;
            fs = scrafter;
            int nmatch = nof(fs);
            for(int j = 0; j < i; j++){
                scrafter[j] = ns[j+1];
            }
            ss = scrafter;
            if(ss != fs){
                nmatch += nof(ss);
                nmatch %= 1000000007;
            }
            cur->push_back(make_pair(ns,nmatch));
        }
        //prv = cur;
        sort(cur->begin(), cur->end());
        vector<pair<string, int> > *cur2;
        cur2 = new vector<pair<string, int> >();
        cur2->push_back(cur->front());
        for(int j = 1; j < cur->size(); j++){
            if((*cur)[j].first == cur2->back().first){
                cur2->back().second += (*cur)[j].second;
                cur2->back().second %= 1000000007;
            }else{
                cur2->push_back((*cur)[j]);
            }
        }
        prv = cur2;
    }
    int tal = 0;
    for(int i = 0; i < prv->size(); i++){
        tal += (*prv)[i].second;
        tal %= 1000000007;
        //cout << tal << " ";
    }
    //cout << endl;
    cout << tal;
}
/*
3 2
a b
ab bd
abc abd

5 2
a b
cb ba
aba ccb
abab accb
accba accbd
*/

Compilation message (stderr)

trener.cpp: In function 'int main()':
trener.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 1; j < prv->size(); j++){
                    ~~^~~~~~~~~~~~~
trener.cpp:73:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1; j < cur->size(); j++){
                        ~~^~~~~~~~~~~~~
trener.cpp:84:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < prv->size(); i++){
                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...