1 solutions

  • -1
    @ 2026-8-3 15:49:49
    #include<bits/stdc++.h>
    using namespace std;
    const int N=2e5+10;
    int a[N];
    bool st[N];
    int main()
    {
    	int n;
    	cin>>n;
    	a[1]=1;
    	st[1]=1;
    	for(int i=1;i<=n;i++)
    	{
    		int x=a[i-1]-i;
    		if(x>0&&st[x]==0)
    		{
    			a[i]=x;
    			st[x]=1;
    		}
    		else
    		{
    			a[i]=a[i-1]+i;
    			st[a[i]]=1;
    		}
    	}
    	sort(a+1,a+n+1);
    	for(int i=1;i<=n;i++)
    	{
    		cout<<a[i]<<" ";
    	}
    	return 0; 
    } 
    
    • 1

    Information

    ID
    2215
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    9
    Tags
    # Submissions
    12
    Accepted
    3
    Uploaded By