Codeforces Round #672 (Div. 2)

Codeforces Round #672 (Div. 2)

A. Cubes Sorting

#include 
//#define int ll
using namespace std;

#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;

void solve() {
     
    int n;
    cin>>n;
    int a,flag=1;
    cin>>a;
    for (int i = 1; i < n; ++i) {
     
        int b;
        cin>>b;
        if (a<=b) flag=0;
        a=b;
    }
    cout<<(flag?"NO":"YES")<<endl;
}

int main() {
     
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
     
        solve();
    }
    return 0;
}

B. Rock and Lever

#include 
//#define int ll
using namespace std;

//#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;

ll b[50];

void solve() {
     
    ll n,a;
    cin>>n;
    memset(b,0,sizeof(b));
    for (int i = 0; i <n; ++i) {
     
        cin>>a;
        int temp=0;
        while (a) temp++,a/=2;
        b[temp]++;
    }
    ll sum=0;
    for (int i = 1; i < 50; ++i) sum+=b[i]*(b[i]-1)/2;
    cout<<sum<<"\n";
}

int main() {
     
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
     
        solve();
    }
    return 0;
}

C1. Pokémon Army (easy version)

#include 
//#define int ll
using namespace std;

//#pragma GCC optimize(2)

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;

int a[maxn],b[maxn];

void solve() {
     
    int n,q;
    ll sum=0;
    cin>>n>>q;
    for (int i = 1; i <= n; ++i) cin>>a[i];
    a[n+1]=0;
    for (int i = 1; i <=n; ++i) {
     
        b[i]=a[i]-a[i-1];
        if (b[i]>0) sum+=b[i];
    }
    cout<<sum<<"\n";
}

int main() {
     
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
     
        solve();
    }
    return 0;
}

D. Rescue Nibel!

#include 
//#define int ll
using namespace std;

#pragma GCC optimize(2)
//#define int ll
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const ll mo = 998244353;
typedef pair<int, int> pii;

int n,k;
pii a[2*maxn];
ll fact[maxn],infact[maxn];

ll pow(ll aa,ll b,ll p){
     
    int res=1;
    while (b){
     
        if (b&1) res=res*aa%p;
        b>>=1;
        aa=aa*aa%p;
    }
    return res;
}

void init(){
     
    fact[0]=infact[0]=1;
    for (int i = 1; i <=n; ++i) {
     
        fact[i]=fact[i-1]*i%mo;
        infact[i]=pow(fact[i],mo-2,mo);
    }
}

void solve() {
     
    cin>>n>>k;
    init();
    for (int i = 1; i <=n; ++i) {
     
        int l,r;
        cin>>l>>r;
        a[i].first=l,a[i].second=-1;
        a[i+n].first=r,a[i+n].second=1;
    }
    sort(a+1,a+2*n+1);
    int sum=0,cnt=0;
    for (int i = 1; i <=2*n; ++i) {
     
        if (a[i].second==-1){
     
            if (cnt>=k-1) sum=(sum+fact[cnt]*infact[k-1]%mo*infact[cnt-k+1]%mo)%mo;
            cnt++;
        }else cnt--;
    }
    cout<<sum<<"\n";
}

signed main() {
     
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
     
        solve();
    }
    return 0;
}

E. Battle Lemmings

#include 
#define int ll
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const int maxn=3e5+10;
const int INF=1e18;
int a[81],pos[82];
int dp[82][82][82*82];

int qc(int x){
     
    return x*(x-1)/2;
}

void solve() {
     
    int n,top=0,ans=0;
    cin>>n;
    for (int i = 1; i <=n; ++i){
     
        cin>>a[i];
        if (a[i]) pos[++top]=i;
        else ans++;
    }
    pos[++top]=n+1;
    int sum=qc(ans),k=qc(n);
    for (int i = 0; i < top+1; ++i) {
     
        for (int j = 0; j < n+2; ++j) {
     
            for (int l = 0; l < k+1; ++l) {
     
                dp[i][j][l]=INF/4;
            }
        }
    }
    dp[0][0][0]=0;
    for (int i = 1; i < top+1; ++i) {
     
        for (int j = i; j < n+2; ++j) {
     
            for (int l= abs(pos[i]-j); l <k+1 ; ++l) {
     
                for (int t = i-1; t < j; ++t) {
     
                    dp[i][j][l]=min(dp[i][j][l],dp[i-1][t][l-abs(pos[i]-j)]+qc(j-t-1));
                }
            }
        }
    }
    for (int i = 0; i < k + 1; ++i) {
     
        if (i) dp[top][n+1][i]=min(dp[top][n+1][i],dp[top][n+1][i-1]);
        cout<<sum-dp[top][n+1][i]<<" ";
    }
    cout<<'\n';
}

signed main() {
     
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
     
        solve();
    }
    return 0;
}

你可能感兴趣的:(cf,cf,acm,div2,c++)