Kattis
C - Cryptographer’s Conundrum
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
inline void solve(){
string s;
cin>>s;
int res=0;
for(int i=0;i<s.size();i++){
if(i%3==0) if(s[i]!='P') res++;
if(i%3==1) if(s[i]!='E') res++;
if(i%3==2) if(s[i]!='R') res++;
}
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
D - Disastrous Downtime
答案
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a, b) memset(a, b, sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i, a, b) for (auto i = a; i <= b; ++i)
#define bep(i, a, b) for (auto i = a; i >= b; --i)
#define lowbit(x) x&(-x)
#define PII pair<int, int>
#define x first
#define y second
#define PLL pair<ll, ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
using namespace std;
map<int, int> mp;
struct node {
int add;
int data;
} a[N];
inline void solve() {
int n, m;
cin >> n >> m;
int k;
for (int i = 1; i <= n; i++) {
cin >> k;
if (!mp.count(k))
mp[k] = 1;
else
mp[k]++;
}
int tot = 0;
int sum = 0, maxx = -1;
for (auto i : mp) {
a[tot++] = {i.x, i.y};
}
for (int i = 0, j = 0; i < tot; i++) {
for (; a[i].add - a[j].add >= 1000 && j < i; j++) //
{
if (a[i].add - a[j].add < 1000) break;
sum -= a[j].data;
}
sum += a[i].data;
maxx = max(sum, maxx);
}
int ans = maxx / m;
if (maxx % m != 0) ans++;
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
E - Entertainment Box
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
struct node{
int x;
int y;
bool operator<(node &a){
return y<a.y;
}
}dp[N];
vector<int>vp;
inline void solve(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>dp[i].x>>dp[i].y;
sort(dp+1,dp+1+n);
for(int i=0;i<k;i++) vp.eb(0);
int res=0;
for(int i=1;i<=n;i++){
auto pos=upper_bound(vp.begin(),vp.end(),dp[i].x);
if(pos!=vp.begin()){
vp.erase(pos-1);
vp.eb(dp[i].y);
res++;
}
}
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
G - Goblin Garden Guards
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 11111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int num[M][M];
inline bool judge(int a,int b,int c,int d,int r){
int len=(a-c)*(a-c)+(b-d)*(b-d);
if(len<=r*r) return 1;
else return 0;
}
inline void solve(){
int n;
cin>>n;
int u,v;
for(int i=1;i<=n;i++){
cin>>u>>v;
num[u][v]++;
}
int m;
cin>>m;
int res=0;
int x,y,r;
while(m--){
cin>>x>>y>>r;
for(int i=max(0,x-r);i<=min(x+r,10000);i++){
for(int j=max(0,y-r);j<=min(y+r,10000);j++){
if(judge(i,j,x,y,r)){
res+=num[i][j];
num[i][j]=0;
}
}
}
}
cout<<n-res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
F - Floppy Music (补)
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int dp[N];
bool vp1[N];
bool vp2[N];
inline void solve(){
int f;
cin>>f;
bool flag=0;
while(f--){
bool book=0;
int t,n;
cin>>t>>n;
int a,b;
for(int i=1;i<=n;i++){
cin>>a>>b;
dp[i]=b-a;
}
for(int i=0;i<=t;i++) vp1[i]=1;
for(int i=1;i<=n;i++){
mem(vp2,0);
for(int j=0;j<=t;j++){
if(vp1[j]){
if(j-dp[i]>=0) vp2[j-dp[i]]=1;
if(j+dp[i]<=t) vp2[j+dp[i]]=1;
}
}
for(int j=0;j<=t;j++) vp1[j]=vp2[j];
}
for(int i=0;i<=t;i++){
if(vp1[i]) book=1;
}
if(!book) flag=1;
}
if(!flag) puts("possible");
else puts("impossible");
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}