답안 #1108439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108439 2024-11-04T06:57:07 Z Tsagana 홀-짝 수열 (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;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 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 -