R2 day2

时间:2024-11-13 08:06:31

简单写一下吧

emmmm,来晚了1h,没赶上,所以没交.......(捂脸

T1

开始读错题了诶

开烤1.2h后

发现是个傻逼题....

排序一下,维护前缀最左,右端点

随机数据我跑的比他们都慢..........

#include<cstdio>
#include<algorithm>
#define LL long long
const int maxn = 2000007;
struct node {
int v,loc;
} a[maxn];
bool cmp(node q,node b) {
if(q.v == b.v) return q.loc <= b.loc;
return q.v > b.v;
}
int n,m;
int main() {
freopen("w.in","r",stdin); freopen("w.out","w",stdout);
LL ans = 0; scanf("%d",&n);
for(int i = 1;i <= n;++ i) scanf("%d",&a[i].v), a[i].loc = i;
std::sort(a + 1, a + n + 1,cmp);
int l = a[1].loc,r = a[1].loc;
ans = a[1].v;
for(int i = 2;i <= n;++ i) {
int k = a[i].loc;
if(k < l) l = k;
if(k > r) r = k;
if(k >= l)ans = std::max(1ll * (k - l + 1) * a[i].v,ans);
if(k <= r)ans = std::max(1ll * (r - k + 1) * a[i].v,ans);
}
printf("%I64d\n",ans);
return 0;
}

T2

emmmm,推了一下式子

发现这个

R2 day2

所以只需要尽可能的合并就行了

#include <cstdio>
int cnt[10000007];
const int mod = 998244353;
#define LL long long
int main() {
freopen("s.in","r",stdin);
freopen("s.out","w",stdout);
int n;
scanf("%d",&n);
int cnt[32] = {0};
for(int i = 1;i <= n;i ++) {
int x; scanf("%d", &x);
for(int j = 0;j < 32;j ++) if(x & (1 << j)) cnt[j] ++;
}
LL ans = 0;
for(int i = 1;i <= n;i++) {
int x = 0;
for (int j = 0;j < 32;j ++) if (cnt[j]) x |= (1 << j), cnt[j] --;
ans = (ans + 1ll * x * x) % mod;
}
printf("%lld\n",ans % mod); return 0;
}

T3

状压dp

记录本行和上一行状态

然后把可行状态抽出来就行了

#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int mod = 1e9 + 7;
inline int read() {
int x = 0;
char c = getchar();
while(c < '0' || c > '9')c = getchar();
while(c <= '9'&& c >= '0')x = x * 10 + c - '0',c = getchar();return x;
return x;
}
int n,m,k;
const int maxn = 17;
int cant[maxn];
bool judge(int s) {
if((s & (s >> 1)) || (s & (s >> 2))) return false;
return true;
}
int s[maxn];
int id[maxn];
int dp[maxn][407][407];
int main() {
n = read() , m= read() - 1,k = read();
for(int t,p,i = 1;i <= k;++ i) {
t = read(),p = read() - 1;
cant[t] |= (1 << p);
}
int T = (1 << m) - 1;
int cnt = 0;
for(int i = 0;i <= T;++ i)
if(judge(i)) s[++ cnt] = i,s[i] = cnt;
for(int i = 0;i <= T;++ i) dp[0][0][i] = 1;
long long ans = 0;
for(int i = 1;i <= n;++ i) {
for(int s1 = 0; s1 <= T;++ s1) {
if(cant[i] & s[s1]) continue;
for(int s2 = 0;s2 <= (i <= 1 ? 1 : T);++ s2) {
if(cant[i - 1] & s2 || ((s1 >> 1) & s2) || ((s1 << 1) & s2) || (s1 & s2)) continue;
for(int s3 = 0;s3 <= (i <= 2 ? 1 : T);++ s3) {
if((s3 & s1) || (cant[i - 2] & s3) || ((s2 >> 1) & s3) || ((s2 << 1) & s3) || (s2 & s3) ) continue;
dp[i][s2][s1] += dp[i - 1][s3][s2];
dp[i][s2][s1] %= mod;
}
if(i == n) {ans += dp[i][s2][s1],ans %= mod;}
}
}
}
printf("%lld\n",ans);
return 0;
}