Submission #1032664

# Submission time Handle Problem Language Result Execution time Memory
1032664 2024-07-24T05:52:31 Z KasymK Street Lamps (APIO19_street_lamps) C++17
0 / 100
1 ms 604 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e5+5;
const ll INF = 1e18;
int v[N];

int main(){
	// freopen("file.txt", "r", stdin);
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if(true){
		// (2x % a, 0)
		// 2x % a == 0
		// if a is odd, then the ans is of length a (the 2 will never
		// contribute)
		// if a is even, then the ans of of length a/2
		ll den = (a%2 == 0 ? a/2 : a);
		if (b){
		  // w (B + 1) mod A = 0
		  if (b/gcd(a, b+1) >= (INF+1)/a)
		    den = INF+1;
		  else
		  	den = a/gcd(a, b+1)*b;
		}
		vector<pair<ll, ll>> v;
		map<ll, ll> mp;
		while(n--){
		  ll l, r;
		  scanf("%lld%lld", &l ,&r);
		  ll _l = l%den, _r = r%den;
		  if (r-l+1 >= den){
		  	printf("%lld\n", den);
		    return 0;
		  }
		  if(_l > _r)
		    v.pb({_l, den-1}), v.pb({0, _r});
		  else
		    v.pb({_l, _r});
		}
		for(auto &[l, r] : v)
		  mp[l] = max(mp[l], r);
		ll r_ = 0, ans = 0;
		for(auto &i : mp){
		  if(i.ss < r_)
		    continue;
		  r_ = max(r_, i.ff);
		  ans += i.ss-r_+1;
		  r_ = i.ss+1;
		}
		printf("%lld\n", ans);
		return 0;
	}
	set<pair<ll, ll>> st;
	while(n--){
		ll l, r;
		scanf("%lld%lld", &l, &r);
		for(ll x = l; x <= r; ++x)
		  st.insert({(x+x/b)%a, x%b});
	}
    ll answer = st.size();
    printf("%lld\n", answer);
	return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%d%d", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld", &l ,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -