mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-20 14:11:43 +00:00
Compare commits
No commits in common. "712609a4662606f34280e50964401388c987435f" and "abf764a938825ea553eb8237f00a718d562b3874" have entirely different histories.
712609a466
...
abf764a938
@ -18,6 +18,26 @@ struct S{
|
|||||||
std::vector<S>s;
|
std::vector<S>s;
|
||||||
std::bitset<maxn> vis;
|
std::bitset<maxn> vis;
|
||||||
|
|
||||||
|
sl void dfs(ll now,ll nans){
|
||||||
|
if(now==n+1){
|
||||||
|
ans=std::max(ans,nans);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(ll i=1;i<=3;i++){
|
||||||
|
if(club[i]>=n/2)continue;
|
||||||
|
club[i]++;
|
||||||
|
dfs(now+1,nans+a[now][i]);
|
||||||
|
club[i]--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sl bool smallsolve(){
|
||||||
|
if(n>10)return false;
|
||||||
|
dfs(0,0);
|
||||||
|
std::cout<<ans<<"\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
sl void solve(){
|
sl void solve(){
|
||||||
std::cin>>n;
|
std::cin>>n;
|
||||||
ans=0;
|
ans=0;
|
||||||
@ -27,6 +47,7 @@ sl void solve(){
|
|||||||
for(ll i=1;i<=n;i++){
|
for(ll i=1;i<=n;i++){
|
||||||
std::cin>>a[i][1]>>a[i][2]>>a[i][3];
|
std::cin>>a[i][1]>>a[i][2]>>a[i][3];
|
||||||
}
|
}
|
||||||
|
if(smallsolve())return;
|
||||||
for(ll i=1;i<=n;i++){
|
for(ll i=1;i<=n;i++){
|
||||||
ll tmp[4];
|
ll tmp[4];
|
||||||
for(ll j=1;j<=3;j++)tmp[j]=a[i][j];
|
for(ll j=1;j<=3;j++)tmp[j]=a[i][j];
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cctype>
|
|
||||||
#include <functional>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
std::string s;
|
|
||||||
std::vector<char> v;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>s;
|
|
||||||
v.reserve(s.size());
|
|
||||||
for(char c:s){
|
|
||||||
if(isdigit(c)){
|
|
||||||
v.emplace_back(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::sort(v.begin(),v.end(),std::greater<>());
|
|
||||||
bool isf=true;
|
|
||||||
for(char c:v){
|
|
||||||
if(isf&&c=='0')continue;
|
|
||||||
isf=false;
|
|
||||||
std::cout<<c;
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
#include <bitset>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define sl static inline
|
|
||||||
|
|
||||||
std::string s;
|
|
||||||
std::bitset<256> mcj,maj;
|
|
||||||
sl ll cj(){return mcj.count();}
|
|
||||||
sl ll aj(){return maj.count();}
|
|
||||||
|
|
||||||
sl void solve(){
|
|
||||||
ll ans=0;
|
|
||||||
mcj.reset();
|
|
||||||
maj.reset();
|
|
||||||
std::cin>>s;
|
|
||||||
for(ll alen=1;alen<s.size()-1;alen++){
|
|
||||||
maj[s[alen-1]]=maj[s[alen-1]]^1;
|
|
||||||
for(ll blen=1;alen+blen<s.size();blen++){
|
|
||||||
for(ll l=1;l*(alen+blen)<s.size();l++){
|
|
||||||
mcj.reset();
|
|
||||||
for(ll ci=l*(alen+blen);ci<s.size();ci++){
|
|
||||||
mcj[s[ci]]=mcj[s[ci]]^1;
|
|
||||||
}
|
|
||||||
if(aj()>cj()){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for(ll i=alen+blen;i<l*(alen+blen);i++){
|
|
||||||
if(s[i%(alen+blen)]!=s[i]){
|
|
||||||
goto nxt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ans++;
|
|
||||||
nxt:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
ll t;
|
|
||||||
std::cin>>t;
|
|
||||||
while(t--){
|
|
||||||
solve();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,98 +0,0 @@
|
|||||||
#include <bits/stdc++.h>
|
|
||||||
using namespace std;
|
|
||||||
using ll = long long;
|
|
||||||
|
|
||||||
const ll maxn = 1e5+7;
|
|
||||||
ll n,a[maxn][4],numclub[3+1],smallans=0;
|
|
||||||
bool viss[maxn];
|
|
||||||
|
|
||||||
#define printf
|
|
||||||
|
|
||||||
static inline void dfs(ll nn,ll nans){
|
|
||||||
if(nn>n){
|
|
||||||
smallans=max(smallans,nans);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ll i=1;i<=3;i++){
|
|
||||||
if(numclub[i]>=n/2)continue;
|
|
||||||
numclub[i]++;
|
|
||||||
dfs(nn+1,nans+a[nn][i]);
|
|
||||||
numclub[i]--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void solvesmall(){
|
|
||||||
smallans=0;
|
|
||||||
numclub[0]=numclub[1]=numclub[2]=numclub[3]=0;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=3;j++){
|
|
||||||
cin>>a[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dfs(1,0);
|
|
||||||
cout<<smallans<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void solve(){
|
|
||||||
ll ans=0;
|
|
||||||
cin>>n;
|
|
||||||
if(n<=11){
|
|
||||||
solvesmall();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
numclub[0]=numclub[1]=numclub[2]=0;
|
|
||||||
for(ll i=0;i<=n;i++)viss[i]=false;
|
|
||||||
struct S{
|
|
||||||
ll diff,size,club,i;
|
|
||||||
inline bool operator<(const S&other)const{
|
|
||||||
if(diff==other.diff)return size>other.size;
|
|
||||||
return diff>other.diff;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
vector<S> s;
|
|
||||||
s.reserve(n+1);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
struct Tmp{
|
|
||||||
ll size,j;
|
|
||||||
inline bool operator<(const Tmp&other)const{
|
|
||||||
return size>other.size;
|
|
||||||
}
|
|
||||||
}tmp[4];
|
|
||||||
for(ll j=1;j<=3;j++){
|
|
||||||
ll b;
|
|
||||||
cin>>b;
|
|
||||||
tmp[j]={b,j};
|
|
||||||
}
|
|
||||||
sort(tmp+1,tmp+1+3);
|
|
||||||
for(ll j=1;j<=3;j++){
|
|
||||||
s.push_back({tmp[j].size-tmp[2].size,tmp[j].size,tmp[j].j,i});
|
|
||||||
// printf("S{diff=%lld, size=%lld, club=%lld, i=%lld}\n",s.back().diff,s.back().size,s.back().club,s.back().i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort(s.begin(),s.end());
|
|
||||||
for(ll i=0;i<s.size();i++){
|
|
||||||
printf("S{diff=%lld, size=%lld, club=%lld, i=%lld}\n",s[i].diff,s[i].size,s[i].club,s[i].i);
|
|
||||||
}
|
|
||||||
for(ll i=0;i<s.size();i++){
|
|
||||||
if(viss[s[i].i])continue;
|
|
||||||
if(numclub[s[i].club]<n/2){
|
|
||||||
numclub[s[i].club]++;
|
|
||||||
viss[s[i].i]=true;
|
|
||||||
ans+=s[i].size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cout<<ans<<"\n";
|
|
||||||
printf("------\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
freopen("club.in","r",stdin);
|
|
||||||
freopen("club.out","w",stdout);
|
|
||||||
iostream::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
ll t;
|
|
||||||
cin>>t;
|
|
||||||
while(t--)solve();
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
#include <bits/stdc++.h>
|
|
||||||
using namespace std;
|
|
||||||
using ll = long long;
|
|
||||||
|
|
||||||
const ll maxn = 500+7,p=998'244'353;
|
|
||||||
ll n,m,a[maxn],ans=0;
|
|
||||||
string s;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
// freopen("employ.in","r",stdin);
|
|
||||||
// freopen("employ.out","w",stdout);
|
|
||||||
iostream::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
cin>>n>>m;
|
|
||||||
cin>>s;
|
|
||||||
s=" "+s;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
cin>>a[i];
|
|
||||||
}
|
|
||||||
sort(a+1,a+1+n);
|
|
||||||
do{
|
|
||||||
ll no=0;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
if(no>=a[i]){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(s[i]=='0'){
|
|
||||||
no++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(n-no>=m)ans=(ans+1)%p;
|
|
||||||
}while(next_permutation(a+1,a+1+n));
|
|
||||||
cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
#include<bits/stdc++.h>
|
|
||||||
using namespace std;
|
|
||||||
using ll = long long;
|
|
||||||
|
|
||||||
const ll maxn = 2e5+7;
|
|
||||||
ll n,q;
|
|
||||||
|
|
||||||
string s[maxn][2],r[maxn][2];
|
|
||||||
static inline bool issame(int idx,const string&a,const string&b){
|
|
||||||
if(idx+b.size()>a.size()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for(int i=0;i<b.size();i++){
|
|
||||||
if(a[i+idx]!=b[i])return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
freopen("replace.in","r",stdin);
|
|
||||||
freopen("replace.out","w",stdout);
|
|
||||||
iostream::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
cin>>n>>q;
|
|
||||||
for(int i=1;i<=n;i++){
|
|
||||||
cin>>s[i][0]>>s[i][1];
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=q;i++){
|
|
||||||
cin>>r[i][0]>>r[i][1];
|
|
||||||
ll ans=0;
|
|
||||||
for(ll j=1;j<=n;j++){
|
|
||||||
for(ll k=0;k<r[i][0].size();k++){
|
|
||||||
if(issame(k,r[i][0],s[j][0])){
|
|
||||||
auto tmp = r[i][0];
|
|
||||||
for(int l=0;l<s[j][0].size();l++){
|
|
||||||
tmp[l+k]=s[j][1][l];
|
|
||||||
}
|
|
||||||
if(tmp==r[i][1])ans++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cout<<ans<<'\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
#include <bits/stdc++.h>
|
|
||||||
using namespace std;
|
|
||||||
using ll = long long;
|
|
||||||
#define sl static inline
|
|
||||||
const int maxm = 1e6+7,maxn=1e4+7;
|
|
||||||
int n,m,k;
|
|
||||||
struct R{
|
|
||||||
int u,v,w;
|
|
||||||
inline bool operator<(const R&o)const{
|
|
||||||
return w<o.w;
|
|
||||||
}
|
|
||||||
}r[maxm];
|
|
||||||
struct C{
|
|
||||||
int w;
|
|
||||||
int cw[maxn];
|
|
||||||
}c[17];
|
|
||||||
|
|
||||||
int bcj[maxm];
|
|
||||||
|
|
||||||
sl ll find(ll n){
|
|
||||||
if(bcj[n]==n)return n;
|
|
||||||
return bcj[n]=find(bcj[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sl bool same(ll a,ll b){
|
|
||||||
return find(a)==find(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
sl void merge(ll a,ll b){
|
|
||||||
bcj[find(a)]=find(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool checkA(){
|
|
||||||
if(k==0)return false;
|
|
||||||
for(int i=1;i<=k;i++){
|
|
||||||
if(c[i].w!=0)return false;
|
|
||||||
}
|
|
||||||
vector<R> vr(r+1,r+1+m);
|
|
||||||
for(int i=1;i<=k;i++){
|
|
||||||
for(ll j=1;j<n;j++){
|
|
||||||
for(ll k=j+1;k<=n;k++){
|
|
||||||
vr.push_back({j,k,c[i].cw[j]+c[i].cw[k]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(int i=1;i<=n;i++)bcj[i]=i;
|
|
||||||
sort(vr.begin(),vr.end());
|
|
||||||
ll ans=0;
|
|
||||||
for(int i=0;i<vr.size();i++){
|
|
||||||
if(same(vr[i].u,vr[i].v))continue;
|
|
||||||
ans+=vr[i].w;
|
|
||||||
merge(vr[i].u,vr[i].v);
|
|
||||||
}
|
|
||||||
cout<<ans<<"\n";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline bool checkB(){
|
|
||||||
if(k!=0)return false;
|
|
||||||
for(int i=1;i<=n;i++)bcj[i]=i;
|
|
||||||
sort(r+1,r+1+m);
|
|
||||||
ll ans=0;
|
|
||||||
for(int i=1;i<=m;i++){
|
|
||||||
if(same(r[i].u,r[i].v))continue;
|
|
||||||
ans+=r[i].w;
|
|
||||||
merge(r[i].u,r[i].v);
|
|
||||||
}
|
|
||||||
cout<<ans<<"\n";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
freopen("road.in","r",stdin);
|
|
||||||
freopen("road.out","w",stdout);
|
|
||||||
iostream::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
cin>>n>>m>>k;
|
|
||||||
for(int i=1;i<=m;i++){
|
|
||||||
cin>>r[i].u>>r[i].v>>r[i].w;
|
|
||||||
}
|
|
||||||
for(int i=1;i<=k;i++){
|
|
||||||
cin>>c[i].w;
|
|
||||||
for(int j=1;j<=n;j++){
|
|
||||||
cin>>c[i].cw[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(checkA()){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(checkB()){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,5 +2,5 @@
|
|||||||
#include <print>
|
#include <print>
|
||||||
#include <source_location>
|
#include <source_location>
|
||||||
int main(){
|
int main(){
|
||||||
std::println("hello world from {}\n",std::source_location::current().file_name());
|
std::println("hello world from {}\n",std::source_location().file_name());
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user