# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
3357 | jiyong3 | 두 섬간의 연결 (kriii1_2) | C++98 | 220 ms | 2452 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
#define MAXN 100000
int n;
int boundary[MAXN+1];
int NumOfConnection[MAXN+1];
void printValue(long long n)
{
long long v1=n*(n+1)/2;
long long 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);
int tmp=boundary[left];
boundary[left]=boundary[t+1];
boundary[right]=(left==t) ? tmp : boundary[t];
NumOfConnection[left]=NumOfConnection[right]=sum;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |