# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3353 | jiyong3 | 두 섬간의 연결 (kriii1_2) | C++98 | 188 ms | 2452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
#define MAXN 100000
int n;
int boundary[MAXN+1];
int NumOfConnection[MAXN+1];
void printValue(int n)
{
int v1=n*(n+1)/2;
int v2=(n*(n+1)*(2*n+1)/6 + v1) / 2;
cout << v1 << " " << v2 << endl;
}
int main()
{
cin >> n;
for(int i=1;i<=n;i++)
{
boundary[i]=i;
NumOfConnection[i]=1;
}
for(int i=0;i<n-1;i++)
{
int t;
cin >> t;
int left=boundary[t];
int right=boundary[t+1];
int sum=NumOfConnection[t]+NumOfConnection[t+1];
printValue(sum-1);
NumOfConnection[left]=NumOfConnection[right]=sum;
int tmp=boundary[left];
boundary[left]=boundary[t+1];
boundary[right]=(left==t) ? tmp : boundary[t];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |