Submission #938458

#TimeUsernameProblemLanguageResultExecution timeMemory
938458BaizhoGap (APIO16_gap)C++14
30 / 100
41 ms3708 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> // #pragma GCC optimize("Ofast,unroll-loops,fast-math") // #pragma GCC target("popcnt,sse3,avx") typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; #define sz size() #define ff first #define ss second #define all(a) a.begin(),a.end() #define pb push_back const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6 const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod const int M = ll(2e5) + 100; const long long inf = 2e18; //const long double eps = 1e-15L; ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; } ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;} void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); } void MinMax(long long, long long, long long *, long long *); long long n, a[M + 10]; long long solve1() { long long l = 1, r = n, low = 0, high = 1e18; while(l <= r) { MinMax(low, high, &a[l], &a[r]); low = a[l ++] + 1; high = a[r --] -1; } long long ans = 0; for(int i = 1; i < n; i ++) ans = max(ans, a[i + 1] - a[i]); return ans; } long long solve2() { MinMax(0ll, 1LL * 1e18, &a[1], &a[n]); long long block = (a[n] - a[1] + n - 2) / (n - 1), ans = 0, prev = a[1]; for(long long l = a[1]; l < a[n]; l += block) { long long x = 0, y = 0; MinMax(l + 1, min(a[n], l + block), &x, &y); if(y != -1) { ans = max(ans, y - prev); prev = y; } } return ans; } long long findGap(int T, int N) { n = N; if(T == 1) return solve1(); return solve2(); } /* **#*=. .*#***- =*#**.. +#***- -+**+:. ..::--===+++=- +****= .+**+= .:-===++++++****+**- =*#**= =+*+=. .:-===++++*************+ -+#+*+ -+*++...:==+++++************#####*. -+#+++ . :=*++--++++*************#%%%%%%%#*. :+#++*. .. .-+++++++*************#%@@@%%%%%*::::.. .+#++*. .. :=*+=+*************#%@@@@%%%%#-:::::::.. .+#+++: . ... .-==+*************#%@@@@%%%*+:::::::.:::. +#+++-.. ... .-=++***********#%@@@@@%%*--::::.::........ .+**++-... ... .-=++*********###%%@%%%#-::::.:...:::......:. ...=+*++=.... ... ==++*******#*##%@@%%%+:::::..:....:.:......:: .::=+#++=..:. .... -+***########%%@@@%*=:::.:....:...---:.::..... ..::=+#+++..-:.. ::.... .==##%%%%%%%@%%#+:::.:.:.-:...:-:.:+--:.::..... ...::==#+++..--:: :::.... =--+==*-:.....::..:::.:..-::.::-:::=:=.:-:.... ...::=+#++*..--:: :::::.... :.:-+:---- : .::...-..--:.-:-::=#+-::--.. . ...:-+*++*:.--:: :::::..... ...:--:::-:.. .: .:-.:-=--:-.::-=**::*.---:. .:-+*+++-.--:: :::::..... .:::+-::-=-: .:.:--:.:---=:::.:::::%+::-= ..:=**++-.:--: :::::...... :==+-=--:-+=. :.:-:.::=*+:.....:..+@*:::+- ..:=+*++=.:--: :::::........ ::-+-=--=+*+**: . ...::+*#*-..........+@@+..:-::. ..:=+#++=.:--: :::::::.......::::=:=--+*+**:*+:.. .::+::-:...........*@@@#-..:.. ..-=%++=..=-: :::::::::....-::..-:::-***+* **#+:..:::...:......:::.-:#@@%#=:...:.. ..-=#+++..=-- ::::::::::::::.:..:.::.-+*** +#*: ==:.:::. ....::::.=:.:=%##+#. : : ..--*+++..--- ::::::::::::-:.: ..:::::-*-+-.%:.#.--:=---:.. ....:*%+:...:-*%*:... ..:-++++..--- :::::::::::::::....=..:.:* .= - . *.:::.:*@@@@%-+#@@@%+:....:#%=.. .:-=*++:.--- ::::::::::::::.::.:::::::+ ..-. ..::.::..:--:-..:+%%%%*=...-%%+ .:-=*=+:.--- -:::::::::::::..::.:...::=...:@= ...:=*=::--:==:::*%@%@@#-..%%##- .:=-*=+-.:-- --:::::::::::::::::. . ..- : %@#+: ..::::..::==+#@%%%%%%#** %%*%#: ..:==*=+-.:=- ---::::::::::::::::. . .- . +#%%#*: .:.:-..: +#@@%@%%%%%%%#++%%##*. ..:==*===..=- ----:::::-:::::... : . .:: ..#%%%**-.:..:. . :*%*:#%@%%%%%%%+%%%%#= ..::=-*===..=- -----::::--::::. :. : .-:.=%+#%%+%- .. .+*#@+:=*%%%%%%%%*%#%%#= ..::-==*++=..=- -----------:::: :..:-.=--::##******=**---. :+#%%%%%#-.-+%%%%%*%%%%%#: ..:::-==++=+..=- ------------::: :::::++===#**###**##==**#*####**%%%%%%%%-. ::#%%**%%%%%+ ...::--===*=+:.-- ===------------:::---=+*+***##**###***#*##=+#***%%%%%%++*.. .-%%#*%%%%%% ...:::--=+=*=+-:-- ++=====--------::-----+*+*#******####**#*#*-#***#%%%%#+: .:. .*%%+%%%%%%= ...::::---+=*=+=:-- **************+++++==++++=**********#%#*#**+*#**#%%%%%%%+: ...-%%+%%%%%%% ..::::----*=*===:=- #######************++++++=++********##%%%#***#**#%%#**#%%%#=:::*#+%%%%%@@* ..::------+=*=+=-== +++++++++++++++++++++++====+++*****####%%%##**####%%%%#**#%%#+:=**%%%%%%@%=:::::::::-------+=*=++-== ++=========-------::::::--::=++**#######%%%#######%%%%%%%%#**#*=+%%%%%%%@@%*=======++++=====+*+=+=== +++++========------::::::=...:+*#########%%%######%%%%%%%%%%%#***%%#%%%%%%%%#+========++++++++++++++ ++++++========------:::::-:....=##########%#######%%%%%%%%%%%%%%##%%%%%%%%%%%##+==+=+++++++++===++++ ++++++++=======---------::-::::::-*####%%%%########%%%%%%%%%%%%%-=##%%%%%%%%%%%%#=-:::::::::---=---- ++++++++++========-------:=::::::::-*##%%%%%########%%%%%%%%%%%%%%%+%%%%#%@%*++*-:==:::........-.... ++++++++++++=========-----=--::::::::-+#%##%########%%%%%%%%%%%%%%%**%%%%#%*:-*-.:..: :.......-.... ++++++++++++++=========---=----:::::::::+#%%#######%%%%#%%%%%%%%%%%%+%%%#%%--::::..:.=.:.......::... **+++++++++++++++=======---=-----::::::::=+*%%####%%%%%#%%%%%%%%%%%%#*%%%%%%+:::::.::++:-:.....::... ***++++++++++++++++=======-=-------::::::::::+%%%%%%%%%%%%%%%%%%%%%%%++*%%%#%#:-::::-+::.:......-... ******++++++++++++++++======---------::::::::::#%%%%%%%%%%%%%%%%%%%%%#+*%%%%%%=:##+...::::::::::-... **********+++++++++++++======----------::::::::+###%%%%%%%%%%%%%%%%%%%=#%%%%%%#+*+=:::::::::::::-::: ************+*++++++++++====+=----------::::::=######%%%%%%%%%%%%%%%%%=+*%%%%%%%@==:::::::::::::-::: ***************+++++++++++==+===--------:-::-+########%%%@%%%%#%%%%##%+:=*%%%%%%%#+-::::::::::::-::: *****************++++++++++++====----------=#*#########%%%%%%%%%%%###%=-:=*%%%%%%*==-:::::::::::-::: ##******************++++++++++=====-----=--+*#######%%%%%%%%%%%%%%%%%%=:-:-=#%%%%=-=++=:::::::::-::: ####*******************++++++++=====--+#+..=*########%%###%%%%%%%%%%%%=-:-:=+%%%+---=-+*::::::::--:: ######*********************++*++=====-#- ..:*###########%%%#%%%%%%%%%%=::-::++%*--::-=:-#+:::::::-:: #########*********************+++====#=. ...:*############%%%%%%%%%%%%+-::-::---::-::=-::+%=:::::-:: ############*******************+++===#: ... .:+#############%%%%%%%%%%=-::--:::::::::-=:*#*+:--::-:: ################****************+++=*=:.. ...-+*########%%%%%%%%%%%%=-:::-:::::::::-*-**#*-------- ####################************+++++*-. . ....:--:-=+***************+-:::::-:::::::::=*+#-------=-- #########################********+*++*-.........::...---===++++++++:::::::::-::::::::=****-------=-- ###########################****#***++*+=:.......:.....--=-----::::-:::::::::::::::-=+%#*#+===----=-- ############################***#*******#+=-.....:.....:-=--:::::::--:::::::--=:::-+*#+==*+========== ################################*********%=:....-......:-.:-::::::--::::-=+**#==+*@*-+++**+=======+= #################################********##*++---:.....:-..:---===++-==+#%#*+*@##+=-:*+++#++++++++++ %%#######%#######################*#*********#%%%#**+++**#--=**##%@%#*#@#*#======---:-*+****+++++++*+ ######################################********###%%%%%%%%%%@%@#**==#*#+=--====-----:+*************** %%%%%############################################*-======**+++====+=-===-:=------=-:**************** %%%%%%%%%##########################################-..::=--======--==----:=-----:-:.*******##*****#* %%%%%%%%%%%%%###################%%##################-..:.:.::------==------:::::--.=********#*****#* %%%%%%%%%%%%%%%%%%%%%%%%%%####%#%%%##################=:..::::-------+==-=::-------:###############** */

Compilation message (stderr)

gap.cpp: In function 'void Freopen(std::string)':
gap.cpp:34:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gap.cpp:34:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...