提出 #1038894


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

int ask(int l,int r){
	cout<<"? "<<l<<" "<<r<<endl;
	return read();
}

int rec(int b,int e){
	if(b==e)
		return 0;
	int w=e-b,s=1;
	while(s<w)s*=2;
	int x=s-w,y=w-s/2;
	if(x<y)
		return ask(e-s,e)-rec(e-s,b);
	else
		return ask(e-s/2,e)+rec(b,e-s/2);
}

signed main(){
	int n=read();
	int s=1;
	while(s<=n)s*=2;
	s/=2;
	int ans=ask(0,s);
	cout<<"! "<<ans+rec(s,n)<<endl;;
}

提出情報

提出日時
問題 A - Array Sum
ユーザ omoitukanai
言語 C++14 (GCC 5.4.1)
得点 100
コード長 1865 Byte
結果 AC
実行時間 8 ms
メモリ 1228 KiB

コンパイルエラー

./Main.cpp: In function ‘ll read()’:
./Main.cpp:38:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&i);
                  ^
./Main.cpp: In function ‘std::string readString()’:
./Main.cpp:60:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",buf);
                 ^
./Main.cpp: In function ‘char* readCharArray()’:
./Main.cpp:68:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",ret);
                 ^

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 24
セット名 テストケース
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt
ケース名 結果 実行時間 メモリ
01-01.txt AC 7 ms 588 KiB
01-02.txt AC 7 ms 596 KiB
01-03.txt AC 7 ms 596 KiB
01-04.txt AC 7 ms 596 KiB
01-05.txt AC 7 ms 972 KiB
01-06.txt AC 7 ms 976 KiB
01-07.txt AC 7 ms 976 KiB
01-08.txt AC 7 ms 976 KiB
01-09.txt AC 7 ms 968 KiB
01-10.txt AC 7 ms 976 KiB
01-11.txt AC 7 ms 1100 KiB
01-12.txt AC 8 ms 1100 KiB
01-13.txt AC 8 ms 1100 KiB
01-14.txt AC 8 ms 1100 KiB
01-15.txt AC 8 ms 1100 KiB
01-16.txt AC 8 ms 1100 KiB
01-17.txt AC 8 ms 1228 KiB
01-18.txt AC 7 ms 1228 KiB
01-19.txt AC 7 ms 852 KiB
01-20.txt AC 7 ms 976 KiB
01-21.txt AC 8 ms 1100 KiB
01-22.txt AC 7 ms 972 KiB
01-23.txt AC 7 ms 976 KiB
01-24.txt AC 8 ms 1100 KiB