Submission #1108439

# Submission time Handle Problem Language Result Execution time Memory
1108439 2024-11-04T06:57:07 Z Tsagana Odd-even (IZhO11_oddeven) C++14
0 / 100
1 ms 508 KB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second

using namespace std;

lnl findsquare(lnl s) {
	if (s == 0 || s == 1) return s;

	lnl l = 1, r = s / 2, ans;
	while (l <= r) {
		lnl M = (l + r) / 2;

		lnl sqr = M * M;
		if (sqr == s) return M;

		if (sqr <= s) {
			l = M + 1;
			ans = M;
		}
		else r = M - 1;
	}
	return ans;
}

void solve () {
	lnl n; cin >> n;
	lnl k = (findsquare((n * 8) + 1) - 1) / 2;	
	lnl s = (n - ((k * (k + 1)) / 2)) * 2;
	if (!s) {cout << k * k; return ;}
	k = (k * k) - 1;
	cout << k + s;

}
int main() {IOS solve(); return 0;}

Compilation message

oddeven.cpp: In function 'long long int findsquare(long long int)':
oddeven.cpp:20:24: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |  lnl l = 1, r = s / 2, ans;
      |                        ^~~
oddeven.cpp: In function 'void solve()':
oddeven.cpp:38:35: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |  lnl k = (findsquare((n * 8) + 1) - 1) / 2;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 336 KB Output isn't correct
8 Halted 0 ms 0 KB -