게임 링크
제목
문제의 의미
\ (n \) 개인 모두가 자신이 좋아하는 음료가 \ (vechorka \) 맛 등을 지금 당신은 \ (\ lceil N / 2 \ rceil의 \) 상자 \는 (vechorka \) , 경우에 따라 두 병이 최대가 물어 얼마나 많은 사람들이 좋아하는 맛을 얻을 수있다.
생각
우리는 먼저 우리가 함께 짝수, 반드시 남아있는 맛을 고려하여 짝수를 긁어에 우선 순위를 부여해야 좋아하는 맛 최대를 얻기 위해 각각의 맛처럼 얼마나 많은 사람들을 기록하고, (1 \) \ 문제에, 어떻게 점은 사람들의 절반을 만날 수 있습니다.
코드는 다음을 달성하기 위해
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, k;
int a[maxn], num[maxn];
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
num[a[i]]++;
}
int ans = 0;
int tot = (n + 1) / 2;
for(int i = 1; i <= k; ++i) {
ans += num[i] / 2 * 2;
tot -= num[i] / 2;
num[i] %= 2;
}
ans += tot;
printf("%d\n", ans);
return 0;
}
B 제목
문제의 의미
당신은 그냥 사용하려는 \을 (N \) 운영되도록 사탕의 총 수 \ (케이 \) , 작업은 두 가지 유형으로 구분된다 :
- 마지막 증가의 수를 증가 \ (+ 1 \) 사탕;
- 감소 \ (1 \) 사탕.
생각
하프 \ (점검 \) .
코드는 다음을 달성하기 위해
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, k;
bool check(int x) {
return (1LL * x * x + 3LL * x) / 2 - n >= k;
}
int main() {
scanf("%d%d", &n, &k);
int ub = n, lb = 1, mid, ans = 0;
while(ub >= lb) {
mid = (ub + lb) >> 1;
if(check(mid)) {
ans = mid;
ub = mid - 1;
} else {
lb = mid + 1;
}
}
printf("%d\n", n - ans);
return 0;
}
C 제목
문제의 의미
총 \ (2N의 \) 개인에서 번호의 첫 번째 행 \ (1 \)를 합니다 (\ N- 형)를 \ 당신이 총 높이 최대을 지금보다 한 사람 중 하나를 선택하려면, 두 번째 행은, 그러나주의는 동일한 수의 그 사람이 아닌 동일 행의 인접하는 단어의 수를 갖도록.
생각
\ (DP는 [I]는 [j는 ] \) 수를 나타내고, \ (나는 \) 상태는 선택된 사람 \ (J \) 의 최대 높이는, \는 (J = 0 \)의 첫 번째 행이 선택 나타낸다 \을 ( J = 1 \) 번째 행의는 \는 (J = 2 \)의 다음 선택되지 않은 \ (DP가 [I] [0 ] = 최대 (DP [I-1] [1], DP [I-1] [2]) + A [I ] DP [I] [1] = 최대 (DP [I-1] [0], DP [I-1] [2]) + B [i]는, DP [I] [2] = 최대 (DP [-I. 1] [0], DP [-I. 1]. 1, DP [-I. 1] [2]) \) .
코드는 다음을 달성하기 위해
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n;
int a[maxn], b[maxn];
LL dp[maxn][3];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for(int i = 1; i <= n; ++i) {
scanf("%d", &b[i]);
}
for(int i = 1; i <= n; ++i) {
dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
dp[i][2] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]));
}
printf("%lld\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
return 0;
}
D 제목
문제의 의미
정의 \ (F \) 함수
경우 \ (P \ GEQ Q \) \ (F (A1 ... AP, B1 ... BQ) = a_1a_2 \ DOTS A_ {. P-Q + 1} b_1a {P-Q + 2} B_2 \ DOTS A_ {P- 1.} B_ {Q- 1.} a_pb_q \) ;
만약 \ (P <Q \) \ (F (A_1 \ DOTS의 a_p, B_1 \ DOTS b_q) = b_1b_2 ... B_ {Q-P a_1b_ P-Q {}} +. 1 A_2 \ DOTS A_ {P}. 1-B-Q {} a_pb_q. 1 \) .
생각
비트 연산자 기여 제 전처리 \ (A_I \) 길이 \ LEN (\) 수에 대한 \ (F \) 활동은 그 길이의 함수를 곱하여 \ LEN (\) 카운트 수.
코드는 다음을 달성하기 위해
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 998244353;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n;
int a[maxn], pw[105], cnt[30];
LL dp[maxn][30];
int main() {
scanf("%d", &n);
pw[0] = 1;
for(int i = 1; i < 30; ++i) {
pw[i] = 1LL * pw[i-1] * 10 % mod;
}
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for(int i = 1; i <= n; ++i) {
int x = a[i], len = 0;
while(x) {
++len;
x /= 10;
}
cnt[len]++;
for(int j = 1; j <= 10; ++j) {
if(len >= j) {
int num = a[i];
for(int k = 0; k < j; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (((dp[i][j] + 1LL * x * pw[k*2] % mod) % mod) + 1LL * x * pw[k*2+1] % mod) % mod;
}
int pp = 2 * j;;
for(int k = j; k < len; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (dp[i][j] + 2LL * x * pw[pp] % mod) % mod;
++pp;
}
} else {
int num = a[i];
for(int k = 0; k < len; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (((dp[i][j] + 1LL * x * pw[k*2] % mod) % mod) + 1LL * x * pw[k*2+1] % mod) % mod;
}
}
}
}
LL ans = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= 10; ++j) {
ans = (ans + 1LL * dp[i][j] * cnt[j] % mod) % mod;
}
}
printf("%lld\n", ans);
return 0;
}
E 제목
문제의 의미
사용자 구성 \ (n \ 시간 m \) 식을 행렬과 크기가 요구하는 모든하면 \ (a \ 배 B \) 서브 매트릭스 내의 최소값.
코드는 다음을 달성하기 위해
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 998244353;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, m, a, b;
LL g, x, y, z;
int mp[3002][3002], dp[3002][3002];
deque<pii> q;
int main() {
scanf("%d%d%d%d", &n, &m, &a, &b);;
scanf("%lld%lld%lld%lld", &g, &x, &y, &z);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
mp[i][j] = g;
g = (1LL * g * x % z + y) % z;
}
}
for(int i = 1; i <= n; ++i) {
while(!q.empty()) q.pop_back();
for(int j = m; j >= 1; --j) {
while(!q.empty() && mp[i][j] < q.front().first) q.pop_front();
q.push_front({mp[i][j], j});
dp[i][j] = q.back().first;
while(!q.empty() && q.back().second >= j + b - 1) q.pop_back();
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
mp[i][j] = dp[i][j];
}
}
for(int j = 1; j <= m; ++j) {
while(!q.empty()) q.pop_back();
for(int i = n; i >= 1; --i) {
while(!q.empty() && mp[i][j] < q.front().first) q.pop_front();
q.push_front({mp[i][j], i});
dp[i][j] = q.back().first;
while(!q.empty() && q.back().second >= i + a - 1) q.pop_back();
}
}
LL ans = 0;
for(int i = 1; i <= n - a + 1; ++i) {
for(int j = 1; j <= m - b + 1; ++j) {
ans += dp[i][j];
}
}
printf("%lld\n", ans);
return 0;
}