-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 1st Universal Cup. Stage 9: Qingdao
- Loading branch information
Showing
5 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
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,48 @@ | ||
/** | ||
* @file 6128.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-10-18 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 1000005 | ||
|
||
int a[maxn]; | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n; | ||
string s, t; | ||
cin >> s >> t; | ||
for (int i = 1; i <= n; i++) a[i] = (s[i - 1] ^ t[i - 1]); | ||
a[n + 1] = 0; | ||
for (int i = n + 1; i; i--) a[i] ^= a[i - 1]; | ||
int cnt = 0; | ||
for (int i = 1; i <= n + 1; i++) cnt += a[i]; | ||
if (cnt == 0) | ||
cout << (int64_t)n * (n + 1) / 2 << endl; | ||
else if (cnt == 2) | ||
cout << 2 * (n - 1) << endl; | ||
else if (cnt == 4) | ||
cout << 6 << endl; | ||
else | ||
cout << 0 << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
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,77 @@ | ||
/** | ||
* @file 6129.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-10-18 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 200005 | ||
|
||
int s[maxn], a[maxn], b[maxn]; | ||
|
||
void solve(void) { | ||
int n, m; | ||
cin >> n >> m; | ||
string sss; | ||
cin >> sss; | ||
int len = sss.size(); | ||
for (int i = 1; i <= len; i++) s[i] = sss[i - 1] - '0'; | ||
for (a[1] = 1; a[1] <= 9; a[1]++) { | ||
bool chk = true; | ||
int p = 1; | ||
for (int j = 1; j <= m && chk; j++) | ||
if (p <= len && s[p] % a[1] == 0) | ||
b[j] = s[p] / a[1], p++; | ||
else if (p + 1 <= len && (s[p] * 10 + s[p + 1]) % a[1] == 0 && (s[p] * 10 + s[p + 1]) / a[1] < 10) | ||
b[j] = (s[p] * 10 + s[p + 1]) / a[1], p += 2; | ||
else | ||
chk = false; | ||
if (!chk) continue; | ||
for (int i = 2; i <= n && chk; i++) { | ||
a[i] = -1; | ||
for (int j = 1; j <= m && chk; j++) { | ||
if (!b[j]) { | ||
if (p <= len && s[p] == 0) | ||
p++; | ||
else | ||
chk = false; | ||
continue; | ||
} | ||
int v = -1; | ||
if (p <= len && s[p] % b[j] == 0) | ||
v = s[p] / b[j], p++; | ||
else if (p + 1 <= len && (s[p] * 10 + s[p + 1]) % b[j] == 0 && (s[p] * 10 + s[p + 1]) / b[j] < 10) | ||
v = (s[p] * 10 + s[p + 1]) / b[j], p += 2; | ||
else | ||
chk = false; | ||
if (a[i] == -1) a[i] = v; | ||
if (a[i] != v) chk = false; | ||
} | ||
} | ||
if (!chk || p != len + 1) continue; | ||
for (int i = 1; i <= n; i++) cout << a[i]; | ||
cout << ' '; | ||
for (int i = 1; i <= m; i++) cout << b[i]; | ||
cout << endl; | ||
return; | ||
} | ||
cout << "Impossible" << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
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,52 @@ | ||
/** | ||
* @file 6130.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-10-18 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 100005 | ||
|
||
int64_t a[maxn], c[maxn]; | ||
int n; | ||
int64_t m; | ||
|
||
bool check(int64_t lim) { | ||
for (int i = 1; i <= n; i++) c[i] = (lim - 1) / a[i] + 1; | ||
int64_t rest = m; | ||
for (int i = 1; i < n && rest >= 0; i++) { | ||
c[i]--, rest--; | ||
if (c[i] > 0) c[i + 1] -= c[i], rest -= 2 * c[i], c[i] = 0; | ||
} | ||
if (c[n] > 0) rest -= 2 * c[n] - 1; | ||
return rest >= 0; | ||
} | ||
|
||
void solve(void) { | ||
cin >> n >> m; | ||
for (int i = 1; i <= n; i++) cin >> a[i]; | ||
int64_t l = 0, r = 1e18; | ||
while (l + 1 < r) { | ||
int64_t mid = (l + r) >> 1; | ||
(check(mid) ? l : r) = mid; | ||
} | ||
cout << l << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
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,42 @@ | ||
/** | ||
* @file 6131.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-10-18 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 1005 | ||
|
||
void solve(void) { | ||
int n, k; | ||
cin >> n >> k; | ||
vector<int> ans; | ||
for (int v = 1; v < n && k; v++) { | ||
bool chk = true; | ||
for (int i = 0; i < n && chk; i++) chk &= ((i ^ v) < n); | ||
if (chk) k--, ans.push_back(v); | ||
} | ||
if (k) return cout << "Impossible" << endl, void(); | ||
for (auto i : ans) { | ||
for (int j = 0; j < n; j++) cout << (i ^ j) + 1 << ' '; | ||
cout << endl; | ||
} | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
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,43 @@ | ||
/** | ||
* @file 6138.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-10-18 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
void solve(void) { | ||
int x, k; | ||
cin >> x >> k; | ||
while (x >= 2 && k) { | ||
int v = x, sum = 0; | ||
while (v) { | ||
int t = v % 10; | ||
v /= 10; | ||
if (t == 8) | ||
sum += 2; | ||
else if (t == 0 || t == 4 || t == 6 || t == 9) | ||
sum++; | ||
} | ||
x = sum, k--; | ||
} | ||
if (k) x ^= k & 1; | ||
cout << x << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |