Submission #223244

# Submission time Handle Problem Language Result Execution time Memory
223244 2020-04-15T06:06:28 Z SomeoneUnknown Trener (COCI20_trener) C++14
110 / 110
151 ms 11896 KB
#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

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 time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1280 KB Output is correct
2 Correct 12 ms 1152 KB Output is correct
3 Correct 11 ms 1152 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 12 ms 1152 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 14 ms 1280 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 11 ms 1152 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 12 ms 1152 KB Output is correct
10 Correct 12 ms 1152 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 138 ms 11636 KB Output is correct
13 Correct 139 ms 11896 KB Output is correct
14 Correct 151 ms 11640 KB Output is correct
15 Correct 136 ms 11640 KB Output is correct
16 Correct 45 ms 6140 KB Output is correct
17 Correct 139 ms 10360 KB Output is correct
18 Correct 144 ms 10360 KB Output is correct
19 Correct 139 ms 10360 KB Output is correct
20 Correct 138 ms 10360 KB Output is correct
21 Correct 139 ms 10360 KB Output is correct
22 Correct 53 ms 6136 KB Output is correct