ARC168

发布时间 2023-12-27 20:59:58作者: MrcFrst

[ARC168A] <Inversion>

之前打了,忘了,懒得想了,咕。

$\texttt{Code}$
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define il inline
#define re register
const int N=3e5+113;
int n,ans;
char a[N];
il int read(){
    re int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
signed main(){
    n=read()-1;
    scanf("%s",a+1);
    int l=1,r=1;
    while(l<=n){
        if(a[l]=='<'){
            l++,r++;
            continue;
        }
        while(r<n&&a[r+1]=='>')r++;
        ans+=(r-l+1)*(r-l+2)/2;
        l=r+1,r=l;
    }
    cout<<ans;
    return 0;
}

[ARC168B] Arbitrary Nim

首先按常规 NIM 检查异或和判掉 \(-1\)。然后如果有两个相同的堆相当于复制一遍过程,没用,可以直接删去。

然后考虑最大的堆里有 \(k\) 个石子,此时若限制为 \(k-1\),则先手一定可以用一前一后的两次操作结束这一个堆,即先手取 \(k-1\),后手只能取 \(1\) 然后结束。

然后先手就必胜了,所以答案是 \(k-1\),如果没有这样的堆就 \(0\)

$\texttt{Code}$
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define re register
map<int,int>cnt;
int n,tot;
il int read(){
    re int x=0;re char c=getchar(),f=0;
    while(c<'0'||c>'9') f|=(c=='-'),c=getchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c&15),c=getchar();
    return f?-x:x;
}
int main(){
    n=read();
    for(re int i=1;i<=n;i++){
        int x=read();
        tot^=x,cnt[x]++;
    }
    if(tot)return puts("-1"),0;
    while(!cnt.empty()){
        auto fnd=--cnt.end();
        cnt.erase(fnd);
        if((*fnd).second&1)return cout<<(*fnd).first-1,0;
    }
    putchar('0');
    return 0;
}