| Task: | Ositus |
| Sender: | ToukoP |
| Submission time: | 2021-10-16 13:39:23 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 40 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 40 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #5 | WRONG ANSWER | 0.01 s | 2, 3 | details |
| #6 | WRONG ANSWER | 0.01 s | 3 | details |
| #7 | WRONG ANSWER | 0.03 s | 3 | details |
Code
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
const int charCount = 26;
int toInt(char c) {
return (int) c - 97;
}
vector<bool> toBinary(long n) {
vector<bool> r;
while(n != 0) {
r.push_back(n % 2 != 0);
n /= 2;
}
return r;
}
unsigned long all(unsigned long len) {
if (len < 0) len = 0;
unsigned long res = 1;
for (unsigned long i = 0; i < len; i++) {
res *= 2;
}
return res;
}
unsigned long isValid(string value, unsigned long parts) {
vector<bool> binary = toBinary(parts);
bool chars [charCount];
fill_n(chars, charCount, false);
chars[toInt(value[0])] = true;
for (unsigned long i = 1; i < value.length(); i++) {
if (i - 1 < binary.size() && binary[i - 1]) {
fill_n(chars, charCount, false);
}
int c = toInt(value[i]);
if (chars[c]) {
return false;
}
chars[c] = true;
}
return true;
}
unsigned long mod = pow(10, 9) + 7;
unsigned long solve(string value) {
unsigned long res = 0, n = pow((long) 2, value.length() -1);
//cout << "Length " << n << endl;
for (unsigned long i = 0; i < n; i++) {
bool valid = isValid(value, i);
if (valid) {
res++;
if (res == mod) res = 0;
}
//cout << value << (valid ? " Valid":"") << endl;
vector<bool> bin = toBinary(i);
for (unsigned long j = 0; j + 1 < value.length(); j++) {
if (j >= bin.size()) {
//cout << ",";
continue;
}
//cout << (bin.at(j) ? "|" : ".");
}
//cout << endl;
}
return res;
}
int main() {
string str;
cin >> str;
cout << solve(str);
}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: WRONG ANSWER
| input |
|---|
| mfyzvoxmppoxcvktmcjkryyocfweub... |
| correct output |
|---|
| 643221148 |
| user output |
|---|
| 0 |
Test 6
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| weinscqmmpgbrlboocvtbptgbahmwv... |
| correct output |
|---|
| 831644159 |
| user output |
|---|
| 0 |
Test 7
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| sxaoxcyrjoeieyinaqxwukgzdnhhsw... |
| correct output |
|---|
| 816016015 |
| user output |
|---|
| 0 |
