Submission

Status:
[PPP][PPP][PPP][PPP][PPPPP]

Score: 100

User: akuyga1

Problemset: ปราสาท

Language: cpp

Time: 0.002 second

Submitted On: 2025-02-26 13:57:06

#include "bits/stdc++.h"
using namespace std;
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin>>N;
	int y,x;
	for(int i=1;1;i++){
	    if(i*i>=N){y=i; break;}
	}
	int temp=(y-1)*(y-1)+(y+y-1+1)/2;
	for(int i=-(y+y-1-1)/2;i<=(y+y-1-1)/2;i++){
	    if(temp+i==N){x=i; break;}
	}
// 	cout<<y<<' '<<x;
	int c=0;
    while(x!=0||y!=1){
	    if((x%2)*(x%2)==y%2){
	        //go direct up
            y--; c++;	        
	    }
	    else{
	        if(x>=0){x--; c++;}
	        else {x++; c++;}
	    }
	}
	cout<<c;
}