CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:Anniiiz
Submission time:2021-10-08 14:11:41 +0300
Language:C++ (C++11)
Status:READY
Result:40
Feedback
groupverdictscore
#1ACCEPTED40
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#50.01 s2, 3details
#60.01 s3details
#70.43 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:23:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < aakkoset.size(); i++) m[aakkoset[i]] = i;
                   ~~^~~~~~~~~~~~~~~~~
input/code.cpp:51:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = k; i < v.size(); i++) {
                       ~~^~~~~~~~~~
input/code.cpp:87:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < relevantit.size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
string s;
ll t[1000010];
ll aa[29];
ll potenssit[1000010];
vector<ll> kerrottavat;
vector<pair<ll,ll>> v;
map<char,int> m;
map<pair<ll,ll>, bool> kartta;
vector<pair<ll,ll>> p[500000];
string aakkoset = "abcdefghijklmnopqrstuvwxyz";

int main() {
  cin >> s;
  ll n = s.size();
  ll valit = n -1;
  //cout << "v " << valit << endl;
  for (int i = 0; i < aakkoset.size(); i++) m[aakkoset[i]] = i;
  ll a = 1;
  aa[m[s[0]]] = 1;
  while (a < n) {
    if (aa[m[s[a]]]) {
      v.push_back({aa[m[s[a]]], a+1});
    }
    aa[m[s[a]]] = a+1;
    a++;
  }
  ll potenssi = 1;
  potenssit[0] = 1;
  for (int i = 1; i < n; i++) {
    potenssi *= 2;
    potenssi %= 1000000007;
    potenssit[i] = potenssi;
  }
  sort(v.begin(), v.end());
  vector<pair<ll,ll>> relevantit;
  ll k = 0;
  for (auto u : v) {
    k++;
    if (u.second - u.first == 1) {
      valit --;
      continue;
    }
    else {
      ll toimiko = 0;
      for (int i = k; i < v.size(); i++) {
        if (v[i].first >= u.second) {
          toimiko++;
          if (!kartta[u]) {
            relevantit.push_back(u);
            kartta[u] = true;
          }
          break;
        }
        if (v[i].second < u.second){
          toimiko++;
          if (v[i].second - v[i].first != 1) {
            if (!kartta[v[i]]) {
              relevantit.push_back(v[i]);
              kartta[v[i]] = true;
            }
            break;
          }
          else {
            break;
          }
        }
      }
      if (!toimiko && !kartta[u]) {
        relevantit.push_back(u);
        kartta[u] = true;
      }
    }
  }
  if (relevantit.size() != 0) {
    sort(relevantit.begin(), relevantit.end());
    //cout << "v " << valit << endl;
    ll loppu = relevantit[0].second;
    ll alku = relevantit[0].first;
    a = 0;
    p[0].push_back(relevantit[0]);
    for (int i = 1; i < relevantit.size(); i++) {
      pair<ll,ll> u = relevantit[i];
      if (u.first < loppu) {
        loppu = u.second;
        p[a].push_back(u);
      }
      if (u.first >= loppu) {
        valit -= (loppu-alku);
        a++;
        alku = u.first;
        loppu = u.second;
        p[a].push_back(u);
      }
    }
    valit -= (loppu-alku);
    //cout << "v " << valit << endl;
    for (int i = 0; i <= a; i++) {
      vector<pair<ll,ll>> u = p[i];
      if (u.size() == 1) {
        kerrottavat.push_back((potenssit[u[0].second-u[0].first]-1)%1000000007);
      }
      else {
        int kokovali = u[u.size()-1].second - u[0].first+1;
        ll kokomatka = potenssit[kokovali-1];
        kokomatka %= 1000000007;
        int eka = u[0].first;
        ll edellinen = 0;
        for (auto x : u) {
          ll edelliset = x.first - edellinen;
          ll vahennettava = potenssit[edellinen-eka]*(potenssit[edelliset]-1)*potenssit[kokovali-x.second];
          if (x.first == eka) vahennettava = potenssit[kokovali-x.second];
          vahennettava %= 1000000007;
          kokomatka -= vahennettava;
          while (kokomatka < 1000000007) kokomatka += 1000000007;
          kokomatka %= 1000000007;
          //cout << kokomatka << " " << vahennettava << " " << kokovali << " " << kokovali-x.second << endl;
          edellinen = x.first;
        }
        kerrottavat.push_back(kokomatka);
      }
    }
  }
  ll vastaus = 1;
  kerrottavat.push_back(potenssit[valit]);
  for (auto u : kerrottavat) {
    //cout << u << " " << vastaus << " kk" << endl;
    vastaus *= u;
    vastaus %= 1000000007;
  }
  cout << vastaus << endl;


  /*for (auto u : v) cout << u.first << " " << u.second << endl;
  cout << endl;
  for (auto u : relevantit) cout << u.first << " " << u.second << endl;
  for (int i = 0; i < 10; i++) {
    if (p[i].empty()) break;
    for (auto u : p[i]) cout << u.first << " " << u.second << " | ";
    cout << endl;
  }
  cout << valit << endl;*/
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
a

correct output
1

user output
1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcdefghij

correct output
512

user output
512

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcabaacbc

correct output
120

user output
120

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
aaxxxxxxaa

correct output
4

user output
4

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
529186574

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
0

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
0