Upload codes: contests

This commit is contained in:
2025-02-28 16:06:22 +00:00
parent 20088c4a66
commit b6243b7378
14 changed files with 574 additions and 0 deletions

View File

@ -0,0 +1,58 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if (dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
char s[M];
int a[M], top;
bool check()
{
int t = top / 2;
for (int i = 0; i <= t; ++i)
if (a[i] != a[top - i])
return true;
return false;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, step = 0;
cin >> n >> s;
top = strlen(s) - 1;
for (int i = 0; i <= top; ++i)
if (s[i] >= '0' && s[i] <= '9')
a[top - i] = s[i] - '0';
else
a[top - i] = s[i] - 55;
while (check()) {
if (step > 30) {
cout << "Impossible!";
return 0;
}
for (int i = 0; i <= top; ++i)
if (top - i >= i)
a[i] += a[top - i];
else
a[i] = a[top - i];
for (int i = 0; i <= top; ++i)
if (a[i] >= n)
a[i + 1]++, a[i] -= n;
if (a[top + 1])
top++;
step++;
}
cout << "STEP=" << step;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <bits/stdc++.h>
#define lo long long
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
const int N = 1e7 + 10;
/*
toothless. #17
@fredcss_dev
*/
lo qpow(lo a, lo b, lo p) {
lo result = 0;
while (b) {
if (b & 1) {
result += a;
result %= p;
}
b >>= 1;
a += a;
a %= p;
}
return result;
}
lo a, b, p;
signed main()
{
cin >> a >> b >> p;
cout << qpow(a, b, p);
return 0;
}

View File

@ -0,0 +1,27 @@
#include <bits/stdc++.h>
#define lo long long
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
const int N = 1e7 + 10;
/*
toothless. #17
@fredcss_dev
<2025/1/21>
*/
int m, n, d[N], w, v;
signed main()
{
cin >> m >> n;
for(int i = 1; i <= n; i++) {
cin >> v >> w;
for(int j = m; j >= v; j--){
d[j] = max(d[j], d[j - v] + w * v);
}
}
printf("%d",d[m]);
return 0;
}

View File

@ -0,0 +1,49 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n, k;
int a[N];
int ans=0;
bool isPrime(int x)
{
if (x == 1)
return false;
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return false;
return true;
}
void dfs(int x, int sum, int cnt)
{
if (x == k) {
if (isPrime(sum))
ans++;
return;
}
for (int i = cnt; i < n; i++) {
dfs(x + 1, sum + a[i], i + 1);
}
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dfs(0, 0, 0);
cout << ans << endl;
return 0;
}`