Skip to content

Commit

Permalink
Merge pull request #1157 from NachiaVivias/deque-palindrome
Browse files Browse the repository at this point in the history
問題追加 Palindromes in Deque
  • Loading branch information
NachiaVivias authored May 28, 2024
2 parents 013b457 + 88a8003 commit 582dd3e
Show file tree
Hide file tree
Showing 15 changed files with 1,130 additions and 0 deletions.
62 changes: 62 additions & 0 deletions string/palindromes_in_deque/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
44 changes: 44 additions & 0 deletions string/palindromes_in_deque/gen/bad_failure_link.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// TLE attack for solutions not using quicklinks or direct links

// s = ababab...ab
// push back 'b' or 'c'

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int len = Q_MAX / 4;

int q = len * 4;
printf("%d\n", q);

auto alphabet = gen.choice(3, 'a', 'z');
gen.shuffle(alphabet.begin(), alphabet.end());

for (int i = 0; i < len; i++) {
printf("0 %c\n", alphabet[0]);
printf("0 %c\n", alphabet[2]);
}

for (int i = 0; i < len; i++) {
int t = gen.uniform(0, 1);
if (gen.uniform_bool()) {
printf("0 %c\n", alphabet[1 + t]);
printf("2\n");
} else {
printf("1 %c\n", alphabet[0 + t]);
printf("3\n");
}
}

return 0;
}
39 changes: 39 additions & 0 deletions string/palindromes_in_deque/gen/binary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
// #include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
// auto gen = Random(seed);

int flag0 = int(seed % 2);
int flag1 = int(seed / 2 % 2);

int maxlen = Q_MAX / 2;

string s;
for (int d = 0; int(s.size() * 2 + 1) < maxlen; d++) {
string t = s + string(1, 'a' + d) + s;
s = t;
}

int len = int(s.size());

int q = len * 2;
printf("%d\n", q);

for (int i = 0; i < len; i++) {
printf("%d %c\n", flag0 ? 0 : 1, s[i]);
}

for (int i = 0; i < len; i++) {
printf("%d\n", flag1 ? 2 : 3);
}

return 0;
}
10 changes: 10 additions & 0 deletions string/palindromes_in_deque/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
9
1 a
1 b
1 c
1 b
1 c
1 b
1 a
3
1 c
13 changes: 13 additions & 0 deletions string/palindromes_in_deque/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
12
0 o
0 x
0 o
1 o
1 x
1 o
2
2
2
3
3
3
43 changes: 43 additions & 0 deletions string/palindromes_in_deque/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "random.h"
#include "../params.h"

using namespace std;

struct Query {
int ty;
char c;
};

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int q = gen.uniform(Q_MIN, Q_MAX);

int current_len = 0;

printf("%d\n", q);

for (int i = 0; i < q; i++) {
int ty = 0;
if (current_len >= 1) {
ty = gen.uniform(0, 3);
}
else {
ty = gen.uniform(0, 1);
}

if (ty == 0 || ty == 1) {
char c = gen.uniform('a', 'z');
printf("%d %c\n", ty, c);
}
else {
printf("%d\n", ty);
}
}

return 0;
}
45 changes: 45 additions & 0 deletions string/palindromes_in_deque/gen/random_small_sigma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "random.h"
#include "../params.h"

using namespace std;

struct Query {
int ty;
char c;
};

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int q = gen.uniform(Q_MIN, Q_MAX);
int sigma = 5;
auto alphabet = gen.choice(sigma, 'a', 'z');

int current_len = 0;

printf("%d\n", q);

for (int i = 0; i < q; i++) {
int ty = 0;
if (current_len >= 1) {
ty = gen.uniform(0, 3);
}
else {
ty = gen.uniform(0, 1);
}

if (ty == 0 || ty == 1) {
char c = alphabet[gen.uniform(0, sigma - 1)];
printf("%d %c\n", ty, c);
}
else {
printf("%d\n", ty);
}
}

return 0;
}
76 changes: 76 additions & 0 deletions string/palindromes_in_deque/gen/short_period.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

vector<string> fixed_period_list = {
string("a"),
string("z"),
string("ab"),
string("zyz"),
string("abc")
};


string period = fixed_period_list.at(seed / 2);
int maxlen = Q_MAX;
if (seed % 2 == 1) maxlen /= 2;
string s;
while (int(s.size() + period.size()) <= maxlen) {
s += period;
}

int len = int(s.size());

int q = len;
int num_insert = len;
int num_delete = 0;
if (seed % 2) {
q = len * 2;
num_delete = q - num_insert;
}

vector<int> sw(q);
for (int i = 0; i < q; i++) sw[i] = gen.uniform_bool();

int pos_p = 0;
for (int i = 0; i < num_insert; i++) pos_p += 1 - sw[i];
int pos_q = pos_p;
int pos_i = 0;

printf("%d\n", q);

for (int i = 0; i < num_insert; i++) {
if (sw[pos_i] == 0) {
pos_p--;
printf("0 %c\n", s[pos_p]);
}
else {
printf("1 %c\n", s[pos_q]);
pos_q++;
}
pos_i++;
}

for (int i = 0; i < num_delete; i++) {
if (sw[pos_i] == 0) {
pos_q--;
printf("2\n");
}
else {
printf("3\n");
pos_p++;
}
pos_i++;
}

return 0;
}
Loading

0 comments on commit 582dd3e

Please sign in to comment.