Submission #19284621


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll floor_sum(ll N,ll M,ll A,ll B) {
	// sum(i=0...N-1) floor((A*i+B)/M)
	
	if(A<=0) return 0;
	
	ll ret=0;
	if(B>=M) ret+=N*(B/M), B%=M;
	if(A>=M) ret+=N*(N-1)/2*(A/M), A%=M;
	
	ll Y=(A*N+B)/M;
	if(Y==0) return ret;
	//floor(Y/M)に達するX
	ll X=Y*M-B;
	//Xの右側はY個ずつ
	ret+=(N-(X+A-1)/A)*Y;
	// 90度回転、Y=Nのラインは無視する
	ret+=floor_sum(Y,A,M,(A-X%A)%A);
	return ret;
}

int T;
ll A,B,C,D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		cin>>A>>B>>C>>D;
		int ma=0;
		for(i=29;i>=0;i--) {
			if(1LL*(C-B)*(ma+(1<<i))<D) ma+=1<<i;
		}
		
		ll ret=floor_sum(ma+1,D,C,A)-floor_sum(ma+1,D,B,A-1);
		cout<<ma-ret<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task E - Simple Math 3
User kmjp
Language C++ (GCC 9.2.1)
Score 800
Code Size 1549 Byte
Status AC
Exec Time 46 ms
Memory 3624 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:40:8: warning: unused variable ‘j’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:40:10: warning: unused variable ‘k’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:40:12: warning: unused variable ‘l’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:40:14: warning: unused variable ‘r’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:40:16: warning: unused variable ‘x’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |                ^
./Main.cpp:40:18: warning: unused variable ‘y’ [-Wunused-variable]
   40 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:61:38: note: in expansion of macro ‘FOR’
   61 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status AC
AC × 21
Set Name Test Cases
Sample
All example_00, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, max_random_05, max_random_06, max_random_07, max_random_08, max_random_09, small_00, small_01, small_02, small_03, small_04, small_bc_00, small_bc_01, small_bc_02, small_bc_03, small_bc_04
Case Name Status Exec Time Memory
example_00 AC 7 ms 3536 KB
max_random_00 AC 30 ms 3460 KB
max_random_01 AC 28 ms 3564 KB
max_random_02 AC 38 ms 3456 KB
max_random_03 AC 34 ms 3584 KB
max_random_04 AC 33 ms 3616 KB
max_random_05 AC 32 ms 3512 KB
max_random_06 AC 31 ms 3584 KB
max_random_07 AC 34 ms 3584 KB
max_random_08 AC 29 ms 3508 KB
max_random_09 AC 28 ms 3480 KB
small_00 AC 32 ms 3480 KB
small_01 AC 30 ms 3540 KB
small_02 AC 25 ms 3536 KB
small_03 AC 32 ms 3588 KB
small_04 AC 28 ms 3512 KB
small_bc_00 AC 45 ms 3460 KB
small_bc_01 AC 44 ms 3624 KB
small_bc_02 AC 42 ms 3584 KB
small_bc_03 AC 46 ms 3488 KB
small_bc_04 AC 45 ms 3532 KB