Submission #3353

#TimeUsernameProblemLanguageResultExecution timeMemory
3353jiyong3두 섬간의 연결 (kriii1_2)C++98
0 / 1
188 ms2452 KiB
#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 timeMemoryGrader output
Fetching results...