Submission #1228232

#TimeUsernameProblemLanguageResultExecution timeMemory
1228232salmonSparklers (JOI17_sparklers)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int N,K;
long long int T;
int lst[100100];

int m;

bool zero;
pair<long long int, long long int> ii;
pair<long long int, long long int> ii1;

int it;
int it1;
	
void propit(){
	if(it == N + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != N + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += - (lst[it] - lst[it - 1]) + T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void propit1(){
	if(it1 == 0){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != 0 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += - (lst[it1 + 1] - lst[it1]) + T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

void properit(){
	if(it == K + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != K + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += (lst[it] - lst[it - 1]) - T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void properit1(){
	if(it1 == K - 1){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != K - 1 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += (lst[it1 + 1] - lst[it1]) - T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

int main(){
	
	scanf(" %d",&N);
	scanf(" %d",&K);
	scanf(" %lld",&T);
	
	for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
	
	int s = 0;
	int e = 1e9;

	while(s != e){
		int m = (s + e)/2;
		
		m *= 2;
		
		::m = m;
		
		__int128 cesh = T * m;
		
		bool zero = false;
		
		int l = K; 
		int r = K;
		
		it = K + 1;
		it1 = K - 1;
		
		propit();
		propit1();
		
		while(l != 1 || r != N){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) - T * m < 0) break;
			if(cesh + min(ii.second,ii1.second) - T * m > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					cesh += ii.second;
					l = it1 + 1;
					propit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					l = it1 + 1;
					propit1();
				}
			}
		}
		
		cesh = T * m;
		cesh *= (N - 1);
		cesh += - lst[N];
		
		int fl = 1;
		int fr = N;
		
		it = 2;
		it1 = N - 1;
		
		properit();
		properit1();
		
		while(fl != K || fr != K){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) < 0) break;
			if(cesh + min(ii.second,ii1.second) > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					fl = it - 1;
					properit();
				}
				else{
					cesh += ii.second;
					fr = it1 + 1;
					properit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					fl = it - 1;#include <bits/stdc++.h>
using namespace std;

int N,K;
long long int T;
int lst[100100];

int m;

bool zero;
pair<long long int, long long int> ii;
pair<long long int, long long int> ii1;

int it;
int it1;
	
void propit(){
	if(it == N + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != N + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += - (lst[it] - lst[it - 1]) + T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void propit1(){
	if(it1 == 0){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != 0 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += - (lst[it1 + 1] - lst[it1]) + T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

void properit(){
	if(it == K + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != K + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += (lst[it] - lst[it - 1]) - T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void properit1(){
	if(it1 == K - 1){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != K - 1 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += (lst[it1 + 1] - lst[it1]) - T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

int main(){
	
	scanf(" %d",&N);
	scanf(" %d",&K);
	scanf(" %lld",&T);
	
	for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
	
	int s = 0;
	int e = 1e9;

	while(s != e){
		int m = (s + e)/2;
		
		m *= 2;
		
		::m = m;
		
		__int128 cesh = T * m;
		
		bool zero = false;
		
		int l = K; 
		int r = K;
		
		it = K + 1;
		it1 = K - 1;
		
		propit();
		propit1();
		
		while(l != 1 || r != N){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) - T * m < 0) break;
			if(cesh + min(ii.second,ii1.second) - T * m > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					cesh += ii.second;
					l = it1 + 1;
					propit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					l = it1 + 1;
					propit1();
				}
			}
		}
		
		cesh = T * m;
		cesh *= (N - 1);
		cesh += - lst[N];
		
		int fl = 1;
		int fr = N;
		
		it = 2;
		it1 = N - 1;
		
		properit();
		properit1();
		
		while(fl != K || fr != K){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) < 0) break;
			if(cesh + min(ii.second,ii1.second) > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					fl = it - 1;
					properit();
				}
				else{
					cesh += ii.second;
					fr = it1 + 1;
					properit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					fl = it - 1;
					properit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					fr = it1 + 1;
					properit1();
				}
			}
		}
		
		//printf("%d %d %d %d %d\n\n",l,r,fl,fr,m/2);
		
		m/= 2;
		
		if(l <= fl && fr <= r){
			e = m;
		}
		else s = m + 1;
	}
	
	printf("%d\n",s);
	
}

					properit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					fr = it1 + 1;
					properit1();
				}
			}
		}
		
		//printf("%d %d %d %d %d\n\n",l,r,fl,fr,m/2);
		
		m/= 2;
		
		if(l <= fl && fr <= r){
			e = m;
		}
		else s = m + 1;
	}
	
	printf("%d\n",s);
	
}
#include <bits/stdc++.h>
using namespace std;

int N,K;
long long int T;
int lst[100100];

int m;

bool zero;
pair<long long int, long long int> ii;
pair<long long int, long long int> ii1;

int it;
int it1;
	
void propit(){
	if(it == N + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != N + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += - (lst[it] - lst[it - 1]) + T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void propit1(){
	if(it1 == 0){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != 0 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += - (lst[it1 + 1] - lst[it1]) + T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

void properit(){
	if(it == K + 1){
		ii = {-1,-1};
		return;
	}
	
	zero = false;
	ii = {0,0};
	while(it != K + 1 && (!zero || ii.first < 0)){
		zero = true;
		ii.first += (lst[it] - lst[it - 1]) - T * m;
		ii.second = min(ii.first,ii.second);
		it++;
	}
}

void properit1(){
	if(it1 == K - 1){
		ii1 = {-1,-1};
		return;
	}
	
	zero = false;
	ii1 = {0,0};
	while(it1 != K - 1 && (!zero || ii1.first < 0)){
		zero = true;
		ii1.first += (lst[it1 + 1] - lst[it1]) - T * m;
		ii1.second = min(ii1.first,ii1.second);
		it1--;
	}
}

int main(){
	
	scanf(" %d",&N);
	scanf(" %d",&K);
	scanf(" %lld",&T);
	
	for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
	
	int s = 0;
	int e = 1e9;

	while(s != e){
		int m = (s + e)/2;
		
		m *= 2;
		
		::m = m;
		
		__int128 cesh = T * m;
		
		bool zero = false;
		
		int l = K; 
		int r = K;
		
		it = K + 1;
		it1 = K - 1;
		
		propit();
		propit1();
		
		while(l != 1 || r != N){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) - T * m < 0) break;
			if(cesh + min(ii.second,ii1.second) - T * m > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					cesh += ii.second;
					l = it1 + 1;
					propit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					r = it - 1;
					propit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					l = it1 + 1;
					propit1();
				}
			}
		}
		
		cesh = T * m;
		cesh *= (N - 1);
		cesh += - lst[N];
		
		int fl = 1;
		int fr = N;
		
		it = 2;
		it1 = N - 1;
		
		properit();
		properit1();
		
		while(fl != K || fr != K){
			if(max(ii.first,ii1.first) < 0) break;
			if(cesh + max(ii.second,ii1.second) < 0) break;
			if(cesh + min(ii.second,ii1.second) > 0){
				if(max(ii.first,ii1.first) == ii.first){
					cesh += ii.first;
					fl = it - 1;
					properit();
				}
				else{
					cesh += ii.second;
					fr = it1 + 1;
					properit1();
				}
			}
			else{
				if(max(ii.second,ii1.second) == ii.second){
					if(ii.first < 0) break;
					
					cesh += ii.first;
					fl = it - 1;
					properit();
				}
				else{
					if(ii1.first < 0) break;
					
					cesh += ii1.first;
					fr = it1 + 1;
					properit1();
				}
			}
		}
		
		//printf("%d %d %d %d %d\n\n",l,r,fl,fr,m/2);
		
		m/= 2;
		
		if(l <= fl && fr <= r){
			e = m;
		}
		else s = m + 1;
	}
	
	printf("%d\n",s);
	
}

Compilation message (stderr)

sparklers.cpp:178:53: error: stray '#' in program
  178 |                                         fl = it - 1;#include <bits/stdc++.h>
      |                                                     ^
sparklers.cpp: In function 'int main()':
sparklers.cpp:178:63: error: 'bits' was not declared in this scope
  178 |                                         fl = it - 1;#include <bits/stdc++.h>
      |                                                               ^~~~
sparklers.cpp:178:68: error: 'stdc' was not declared in this scope; did you mean 'std'?
  178 |                                         fl = it - 1;#include <bits/stdc++.h>
      |                                                                    ^~~~
      |                                                                    std
sparklers.cpp:178:54: error: 'include' was not declared in this scope
  178 |                                         fl = it - 1;#include <bits/stdc++.h>
      |                                                      ^~~~~~~
sparklers.cpp:179:1: error: expected primary-expression before 'using'
  179 | using namespace std;
      | ^~~~~
sparklers.cpp:194:14: error: a function-definition is not allowed here before '{' token
  194 | void propit(){
      |              ^
sparklers.cpp:210:15: error: a function-definition is not allowed here before '{' token
  210 | void propit1(){
      |               ^
sparklers.cpp:226:16: error: a function-definition is not allowed here before '{' token
  226 | void properit(){
      |                ^
sparklers.cpp:242:17: error: a function-definition is not allowed here before '{' token
  242 | void properit1(){
      |                 ^
sparklers.cpp:258:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  258 | int main(){
      |         ^~
sparklers.cpp:258:9: note: remove parentheses to default-initialize a variable
  258 | int main(){
      |         ^~
      |         --
sparklers.cpp:258:9: note: or replace parentheses with braces to value-initialize a variable
sparklers.cpp:258:11: error: a function-definition is not allowed here before '{' token
  258 | int main(){
      |           ^
sparklers.cpp: At global scope:
sparklers.cpp:410:5: error: redefinition of 'int N'
  410 | int N,K;
      |     ^
sparklers.cpp:4:5: note: 'int N' previously declared here
    4 | int N,K;
      |     ^
sparklers.cpp:410:7: error: redefinition of 'int K'
  410 | int N,K;
      |       ^
sparklers.cpp:4:7: note: 'int K' previously declared here
    4 | int N,K;
      |       ^
sparklers.cpp:411:15: error: redefinition of 'long long int T'
  411 | long long int T;
      |               ^
sparklers.cpp:5:15: note: 'long long int T' previously declared here
    5 | long long int T;
      |               ^
sparklers.cpp:412:5: error: redefinition of 'int lst [100100]'
  412 | int lst[100100];
      |     ^~~
sparklers.cpp:6:5: note: 'int lst [100100]' previously declared here
    6 | int lst[100100];
      |     ^~~
sparklers.cpp:414:5: error: redefinition of 'int m'
  414 | int m;
      |     ^
sparklers.cpp:8:5: note: 'int m' previously declared here
    8 | int m;
      |     ^
sparklers.cpp:416:6: error: redefinition of 'bool zero'
  416 | bool zero;
      |      ^~~~
sparklers.cpp:10:6: note: 'bool zero' previously declared here
   10 | bool zero;
      |      ^~~~
sparklers.cpp:417:36: error: redefinition of 'std::pair<long long int, long long int> ii'
  417 | pair<long long int, long long int> ii;
      |                                    ^~
sparklers.cpp:11:36: note: 'std::pair<long long int, long long int> ii' previously defined here
   11 | pair<long long int, long long int> ii;
      |                                    ^~
sparklers.cpp:418:36: error: redefinition of 'std::pair<long long int, long long int> ii1'
  418 | pair<long long int, long long int> ii1;
      |                                    ^~~
sparklers.cpp:12:36: note: 'std::pair<long long int, long long int> ii1' previously defined here
   12 | pair<long long int, long long int> ii1;
      |                                    ^~~
sparklers.cpp:420:5: error: redefinition of 'int it'
  420 | int it;
      |     ^~
sparklers.cpp:14:5: note: 'int it' previously declared here
   14 | int it;
      |     ^~
sparklers.cpp:421:5: error: redefinition of 'int it1'
  421 | int it1;
      |     ^~~
sparklers.cpp:15:5: note: 'int it1' previously declared here
   15 | int it1;
      |     ^~~
sparklers.cpp:423:6: error: redefinition of 'void propit()'
  423 | void propit(){
      |      ^~~~~~
sparklers.cpp:17:6: note: 'void propit()' previously defined here
   17 | void propit(){
      |      ^~~~~~
sparklers.cpp:439:6: error: redefinition of 'void propit1()'
  439 | void propit1(){
      |      ^~~~~~~
sparklers.cpp:33:6: note: 'void propit1()' previously defined here
   33 | void propit1(){
      |      ^~~~~~~
sparklers.cpp:455:6: error: redefinition of 'void properit()'
  455 | void properit(){
      |      ^~~~~~~~
sparklers.cpp:49:6: note: 'void properit()' previously defined here
   49 | void properit(){
      |      ^~~~~~~~
sparklers.cpp:471:6: error: redefinition of 'void properit1()'
  471 | void properit1(){
      |      ^~~~~~~~~
sparklers.cpp:65:6: note: 'void properit1()' previously defined here
   65 | void properit1(){
      |      ^~~~~~~~~
sparklers.cpp:487:5: error: redefinition of 'int main()'
  487 | int main(){
      |     ^~~~
sparklers.cpp:81:5: note: 'int main()' previously defined here
   81 | int main(){
      |     ^~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
sparklers.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         scanf(" %d",&K);
      |         ~~~~~^~~~~~~~~~
sparklers.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         scanf(" %lld",&T);
      |         ~~~~~^~~~~~~~~~~~
sparklers.cpp:87:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:489:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  489 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
sparklers.cpp:490:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  490 |         scanf(" %d",&K);
      |         ~~~~~^~~~~~~~~~
sparklers.cpp:491:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  491 |         scanf(" %lld",&T);
      |         ~~~~~^~~~~~~~~~~~
sparklers.cpp:493:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  493 |         for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~