The Solutions of Hydro.ac-Undertale

The Solutions of Hydro.ac-Undertale


Hydro.ac-Undertale

U1000

#include<bits/stdc++.h>
using namespace std;
int main(){
    printf("DETERMINATION\n");
    return 0;
}

U1001

#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
    return 0;
}

U1002

#include<bits/stdc++.h>
using namespace std;
int a[39],T,n,t,q;
int main(){
	register int i,j;
    scanf("%d",&T);
	while(T--){
	scanf("%d",&n),q=0,memset(a,0,sizeof(a));
	for(i=1;i<=n;i++){
		scanf("%d",&t);
		for(j=0;(1<<j)<=t;j++) if((t>>j)&1)a[j]++;
	}
	for(j=0;j<30;j++)if(a[j]){if(!q)q=a[j];else q=std::__gcd(q,a[j]);}
	if(!q){
		for(i=1;i<n;i++)printf("%d ",i);
		printf("%d\n",i);
		continue; 
	}
	for(i=1;i<q;i++)if(q%i==0)printf("%d ",i);printf("%d\n",q);}
	return 0;
}

U1003

#include<bits/stdc++.h>
using namespace std;
int N,a[100039];
int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){scanf("%d",&a[i]);}
    sort(a+1,a+1+N);
    for(int i=1;i<=N;i++){printf("%d ",a[i]);}printf("\n");
    return 0;
}

U1004

#include <bits/stdc++.h>
#define N 1000010
using namespace std;
queue<int> q;
int f[N],a[N],b[N],v[N],pre[N],c[N],l,pass[N];
int find(int x){ if(f[x]==x)return x; return f[x]=find(f[x]); }
void uni(int x,int y) { f[find(x)]=find(y); }
int main(){
	int n,i,j,u; scanf("%d",&n); 
	for(i=1;i<=n;i++) scanf("%d",&a[i]),f[i]=i;f[n+1]=n+1,f[n+2]=n+2;
	for(i=1;i<=n;i++) scanf("%d",&b[i]),b[i]=b[i]+i; v[n]=1;
	q.push(n);
	while(!q.empty()){
		u=q.front();q.pop();
		j=u-a[u];
		for(;j<=u-1;j=find(j)+1)
			if(!v[b[j]])
				uni(j-1,j),v[b[j]]=1,q.push(b[j]),pre[b[j]]=u,pass[b[j]]=j;
			else uni(j-1,j);
	}
	if(!v[0])return printf("Chara is going to erase the world."),0; 
	c[++l]=0; 
	while(c[l]!=n) c[l+1]=pre[c[l]],l++; printf("%d\n",l-1);
	for(i=l-1;i>1;i--) printf("%d ",pass[c[i]]);printf("%d",pass[c[i]]); return 0;
}

U1005

#include<bits/stdc++.h>
using namespace std;
int N,K;
int main(){
	scanf("%d%d",&N,&K);
	for(int i=1;i<K;i++){N/=(N<=2)?1:2;}
	printf("%d",N);
}

U1006

#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\n",max(a,max(b,c)));
    return 0;
}

U1007

#include<bits/stdc++.h>
using namespace std;
int N,a;
string str;
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d%*d",&a);
		int l=0,r=a+1,m;
		while(l+1<r){
			m=(l+r)>>1;
			cout<<m<<endl;
			cin>>str;
			if(str=="right")break;
			else if(str=="large")r=m;
			else if(str=="small")l=m;
		}
	}
}

enclosure

config.yaml:

type: interactive
interactor: interactor.cc

interactor.cc:

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
    setName("Undyne's attack");
    registerInteraction(argc, argv);
    int N=inf.readInt(),a,b,ans,ret,num;
    cout<<N<<endl;
    while(N--){
    	a=inf.readInt();b=inf.readInt();ans=inf.readInt();
    	cout<<a<<" "<<b<<endl;
    	cin>>ret;num=0;
    	while(ret!=ans){
    		num++;if(num>b)quitf(_wa,"You asked too many times!");
    		if(ret>ans)cout<<"large"<<endl;
    		if(ret<ans)cout<<"small"<<endl;
    		cin>>ret;
		}
		cout<<"right"<<endl;
	}
    quitf(_ok,"You blocked all undyne's attack.");
}

U1008,U1009

#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
char S[1010];
struct edge {
	int to;
	edge *nex;
}*head[2000010];
int v[2000010];
void add(int u,int v) {
	edge *cur=new edge;
	cur->to=v;
	cur->nex=head[u];
	head[u]=cur;
}
int n,m,k;
int c(int x,int y,int p) {
	return (x-1)*m*k+(y-1)*k+p-1;
}
int main() {
	int i,j,l,tp;
	int x1,y1,x2,y2;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1; i<=n; i++) {
		scanf("%s",S+1);
		for(j=1; j<=m; j++) if(S[j]=='A') a[i][j]=1;
	}
	for(l=1; l<k; l++) {
		for(i=1; i<=n; i++) {
			for(j=1; j<=m; j++) {
				scanf("%d",&tp);
				if(tp&1) {
					if(i>1) {
						add(c(i,j,l),c(i-1,j,l+a[i-1][j]));
					}
				}
				tp>>=1;
				if(tp&1) {
					if(i<n) {
						add(c(i,j,l),c(i+1,j,l+a[i+1][j]));
					}
				}
				tp>>=1;
				if(tp&1) {
					if(j>1) {
						add(c(i,j,l),c(i,j-1,l+a[i][j-1]));
					}
				}
				tp>>=1;
				if(tp&1) {
					if(j<m) {
						add(c(i,j,l),c(i,j+1,l+a[i][j+1]));
					}
				}
			}
		}
	}
	for(i=1; i<=n; i++) {
		for(j=1; j<=m; j++) {
			scanf("%d",&tp);
			if(tp&1) {
				if(i>1) {
					add(c(i,j,l),c(i-1,j,a[i-1][j]? 1:l));
				}
			}
			tp>>=1;
			if(tp&1) {
				if(i<n) {
					add(c(i,j,l),c(i+1,j,a[i-1][j]? 1:l));
				}
			}
			tp>>=1;
			if(k&1) {
				if(j>1) {
					add(c(i,j,l),c(i,j-1,a[i-1][j]? 1:l));
				}
			}
			tp>>=1;
			if(tp&1) {
				if(j<m) {
					add(c(i,j,l),c(i,j+1,a[i-1][j]? 1:l));
				}
			}
		}
	}
	int s=c(n,m,k+1),t=c(n,m,k+2);
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	for(l=1; l<=k; l++) {
		add(s,c(x1,y1,l));
		add(c(x2,y2,l),t);
	}
	queue<int> q;
	q.push(s);
	v[s]=1;
	while(!q.empty()) {
		int u=q.front();
		q.pop();
		for(edge *cur=head[u]; cur; cur=cur->nex) {
			if(!v[cur->to]) {
				q.push(cur->to),v[cur->to]=v[u]+1;
				if(cur->to==t) break;
			}
		}
	}
	if(v[t]) printf("%d",v[t]-3);
	else printf("what should I do.");
	return 0;
}

U1010,U1011

#include<bits/stdc++.h>
using namespace std;
int T;int a,b,c,d,e,f,g,h,k;
int ans;
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);ans=0;
		k=a/f+(a%f?1:0);ans+=(k*b>=d)?1:0;ans+=((a/f*f)*g+c>e)?1:0;ans+=(k*h+c>e)?1:0;
		ans?
		printf("Alphys will fix it!\n%d\n",ans):
		printf("Where is Alphys!\nWhat should Frisk do!\n");
	}
}

U1012

#include<bits/stdc++.h>
using namespace std;
bool is_prime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){return 0;}}return 1;}
int q,a;
int main(){
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d",&a);printf(is_prime(a)?"Yes\n":"No\n");
	}
	return 0;
}

U1013

#include<bits/stdc++.h>
#include"LOVE.h"
using namespace std;
long long N,K,a,ans;
int main(){
	scanf("%lld%lld",&N,&K);
	for(int i=1;i<=N;i++){
		scanf("%lld",&a);
		ans+=EXP(a);
	}
	if(ans>=K)submit(1);
	else submit(0);
}

enclosure

config.yaml:

type: default

checker_type: testlib
checker: spj.cc

user_extra_files:
  -  LOVE.h

LOVE.h:

#include<bits/stdc++.h>
using namespace std;
namespace Loves {
    static bool hasSubmitted = false;
    void RE() {
        puts("re");
        exit(0);
    }
    int EXP(int x) {
        return (int)((log2(x)*sqrt(x)+x)*(x*log(x)))%100000+1;
    }
    void submit(bool x) {
        if(hasSubmitted)RE();
        printf("%d\n",x?665656:665655);
        hasSubmitted=1;
    }
}
using Loves::RE;
using Loves::EXP;
using Loves::submit;

spj.cc:

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
    registerTestlibCmd(argc, argv);
    int anw=ans.readInt();
    int out=ouf.readInt();
    if (anw==out)
        quitf(_ok, "Correct");
    else{
        if(anw==665655)quitf(_wa,"You need not be judged.");
        else quitf(_wa,"You can't escape judgment.");
    }
}

U1014

#include <bits/stdc++.h>
#define int long long
#define M 1000000007ll
int calc(int n) {
	register int i,j,ans=0;
	for(i=0; i<=n; i++) for(j=0; j<=n-i; j++) ans+=(i&j)%M+(i|j)%M+(i^j)%M,ans%=M;
	return ans;
}
int qpow(int x,int y) {
	int rev=1;
	x%=M;
	while(y) {
		if(y%2==1) rev=rev*x%M;
		x=x*x%M;
		y=y/2;
	}
	return rev;
}
int f[100],fr[100];
int calc2(int n,int c) {
	int x=((n+2)>>(c+1))-1,p;
	p=x%M;
	int ans=fr[c]*fr[c]%M*(p*(p+1)%M)%M*qpow(2,M-2)%M;
	n=n-f[c+1]*x;
	if(n<2*f[c]) return ans;
	else if(n<3*f[c]) {
		p=n%M-fr[c]*2%M+1;
		p=(p%M+M)%M;
		return (ans+(x+1)%M*(p+1)%M*p%M*qpow(2,M-2)%M)%M;
	} else {
		p=fr[c]*4%M-2-n%M;
		p=(p%M+M)%M;
		return (ans+(x+1)%M*(fr[c]*fr[c]%M-p*(p+1)%M*qpow(2,M-2)%M)%M+M)%M;
	}
}

signed main() {
	f[0]=fr[0]=1;
	register int i,n;
	scanf("%lld",&n);
	for(i=1; i<=62; i++) f[i]=f[i-1]*2,fr[i]=fr[i-1]*2%M;
	int pre=(n%M*((n+1)%M)%M*((2*n+1)%M)%M*qpow(3,M-2)%M+(n+1)%M*(n%M)%M)%M;
	int ans=0;
	for(i=0; i<=60; i++) ans+=fr[i]*calc2(n,i)%M,ans%=M;
	ans=ans*2%M;
	printf("%lld\n",((pre-ans)%M+M)%M);
	return 0;
}
上一篇:OS Midterm 1 - Solutions


下一篇:linux install mysql & errors solutions