forked from yosupo06/library-checker-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request yosupo06#1255 from ecottea/create_min_plus_convolu…
…tion_concave_arbitrary 問題追加 Min Plus Convolution (Concave and Arbitrary)
- Loading branch information
Showing
19 changed files
with
727 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
convolution/min_plus_convolution_concave_arbitrary/checker.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
convolution/min_plus_convolution_concave_arbitrary/gen/common.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
vector<ll> rand_gen(Random& gen, int N, int min_slope, int max_slope) { | ||
vector<ll> A(N); | ||
while (1) { | ||
vector<int> slope(N - 1); | ||
for (int i = 0; i < N - 1; ++i) { | ||
slope[i] = gen.uniform<int>(min_slope, max_slope); | ||
} | ||
sort(slope.begin(), slope.end()); | ||
for (int i = 0; i < N - 1; ++i) A[i + 1] = A[i] + slope[i]; | ||
ll mi = *(min_element(A.begin(), A.end())); | ||
ll ma = *(max_element(A.begin(), A.end())); | ||
if (ma - mi > A_MAX) continue; | ||
for (int i = 0; i < N; ++i) A[i] -= mi; | ||
ma -= mi; | ||
int add = gen.uniform<int>(0, A_MAX - ma); | ||
for (int i = 0; i < N; ++i) A[i] += add; | ||
break; | ||
} | ||
return A; | ||
} | ||
|
||
vector<ll> rand_B(Random& gen, int N) { | ||
vector<ll> B(N); | ||
for (int i = 0; i < N; ++i) B[i] = gen.uniform<int>(A_MIN, A_MAX); | ||
return B; | ||
} | ||
|
||
void upside_down(vector<ll>& A){ | ||
int N = A.size(); | ||
for (int i = 0; i < N; ++i) A[i] = A_MAX + A_MIN - A[i]; | ||
} | ||
|
||
void out(vector<ll>& A, vector<ll>& B) { | ||
int n = A.size(), m = B.size(); | ||
printf("%d %d\n", n, m); | ||
for (int i = 0; i < n; ++i) { | ||
if (i) printf(" "); | ||
printf("%lld", A[i]); | ||
} | ||
printf("\n"); | ||
for (int i = 0; i < m; ++i) { | ||
if (i) printf(" "); | ||
printf("%lld", B[i]); | ||
} | ||
printf("\n"); | ||
} |
3 changes: 3 additions & 0 deletions
3
convolution/min_plus_convolution_concave_arbitrary/gen/example_00.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
4 5 | ||
0 2 3 1 | ||
5 1 3 3 2 |
3 changes: 3 additions & 0 deletions
3
convolution/min_plus_convolution_concave_arbitrary/gen/hack_00.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
17 8 | ||
127 127 126 124 121 117 112 106 99 91 82 72 61 49 36 22 7 | ||
100000 100000 100000 100000 100000 100000 100000 2 |
26 changes: 26 additions & 0 deletions
26
convolution/min_plus_convolution_concave_arbitrary/gen/large_small.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int ns[] = {N_MAX, N_MAX, 1, 2}; | ||
int ms[] = {1, 2, N_MAX, N_MAX}; | ||
|
||
int n = ns[seed % 4]; | ||
int m = ms[seed % 4]; | ||
|
||
int LIM_1 = A_MAX / n; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
convolution/min_plus_convolution_concave_arbitrary/gen/max_random.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = N_MAX; | ||
int m = N_MAX; | ||
|
||
int LIM_1 = A_MAX / n * 3; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
convolution/min_plus_convolution_concave_arbitrary/gen/med_random.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = gen.uniform<int>(100, 1000); | ||
int m = gen.uniform<int>(100, 1000); | ||
|
||
int LIM_1 = A_MAX / n * 3; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
convolution/min_plus_convolution_concave_arbitrary/gen/monotone.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = N_MAX; | ||
int m = N_MAX; | ||
|
||
int LIM = A_MAX / n * 2; | ||
int lo_1 = (seed & 1 ? -LIM : 0); | ||
int hi_1 = (seed & 1 ? 0 : LIM); | ||
|
||
vector<ll> A = rand_gen(gen, n, lo_1, hi_1); | ||
vector<ll> B = rand_B(gen, m); | ||
sort(B.begin(), B.end()); | ||
if (seed & 2) reverse(B.begin(), B.end()); | ||
|
||
for (int i = 0; i < n - 1; ++i) { | ||
if (!(seed & 1)) assert(A[i] <= A[i + 1]); | ||
if (seed & 1) assert(A[i] >= A[i + 1]); | ||
} | ||
for (int i = 0; i < m - 1; ++i) { | ||
if (!(seed & 2)) assert(B[i] <= B[i + 1]); | ||
if (seed & 2) assert(B[i] >= B[i + 1]); | ||
} | ||
|
||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
convolution/min_plus_convolution_concave_arbitrary/gen/near_power_of_2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int X = 1 << 18; | ||
int a = X - 1, b = X, c = X + 1; | ||
int ns[] = {a, a, a, b, b, b, c, c, c}; | ||
int ms[] = {a, b, c, a, b, c, a, b, c}; | ||
|
||
int n = ns[seed % 9]; | ||
int m = ms[seed % 9]; | ||
|
||
int LIM_1 = A_MAX / n * 3; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
30 changes: 30 additions & 0 deletions
30
convolution/min_plus_convolution_concave_arbitrary/gen/only_first_small.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = N_MAX; | ||
int m = N_MAX; | ||
|
||
int LIM_1 = A_MAX / n * 3; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B(m); | ||
for (int i = 0; i < m; ++i) { | ||
B[i] = gen.uniform<int>(A_MAX * 9 / 10, A_MAX); | ||
} | ||
|
||
int idx = (seed % 2 == 0 ? 0 : m - 1); | ||
B[idx] = A_MIN; | ||
|
||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
convolution/min_plus_convolution_concave_arbitrary/gen/random.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = gen.uniform<int>(1, N_MAX); | ||
int m = gen.uniform<int>(1, N_MAX); | ||
|
||
int LIM_1 = A_MAX / n * 3; | ||
|
||
vector<ll> A = rand_gen(gen, n, -LIM_1, +LIM_1); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
24 changes: 24 additions & 0 deletions
24
convolution/min_plus_convolution_concave_arbitrary/gen/small.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int ns[] = {1, 1, 1, 2, 2, 2, 3, 3, 3}; | ||
int ms[] = {1, 2, 3, 1, 2, 3, 1, 2, 3}; | ||
|
||
int n = ns[seed % 9]; | ||
int m = ms[seed % 9]; | ||
|
||
vector<ll> A = rand_gen(gen, n, -A_MAX, +A_MAX); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
21 changes: 21 additions & 0 deletions
21
convolution/min_plus_convolution_concave_arbitrary/gen/small_slopes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <cstdio> | ||
#include "../params.h" | ||
#include "random.h" | ||
#include <vector> | ||
|
||
#include "common.hpp" | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int n = N_MAX; | ||
int m = N_MAX; | ||
|
||
vector<ll> A = rand_gen(gen, n, -10, +10); | ||
vector<ll> B = rand_B(gen, m); | ||
upside_down(A); | ||
out(A, B); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.