fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. vector < vector < int > > finalVec;
  13.  
  14. void printArray(int p[], int n)
  15. {
  16. vector < int > vec;
  17. for (int i = 0; i < n; i++)
  18. vec.push_back(p[i]);
  19. finalVec.push_back(vec);
  20. return;
  21. }
  22.  
  23. void printAllUniqueParts(int n)
  24. {
  25. int p[n]; // An array to store a partition
  26. int k = 0; // Index of last element in a partition
  27. p[k] = n; // Initialize first partition as number itself
  28.  
  29. // This loop first prints current partition, then generates next
  30. // partition. The loop stops when the current partition has all 1s
  31. while (true)
  32. {
  33. // print current partition
  34. printArray(p, k+1);
  35.  
  36. // Generate next partition
  37.  
  38. // Find the rightmost non-one value in p[]. Also, update the
  39. // rem_val so that we know how much value can be accommodated
  40. int rem_val = 0;
  41. while (k >= 0 && p[k] == 1)
  42. {
  43. rem_val += p[k];
  44. k--;
  45. }
  46.  
  47. // if k < 0, all the values are 1 so there are no more partitions
  48. if (k < 0) return;
  49.  
  50. // Decrease the p[k] found above and adjust the rem_val
  51. p[k]--;
  52. rem_val++;
  53.  
  54.  
  55. // If rem_val is more, then the sorted order is violeted. Divide
  56. // rem_val in differnt values of size p[k] and copy these values at
  57. // different positions after p[k]
  58. while (rem_val > p[k])
  59. {
  60. p[k+1] = p[k];
  61. rem_val = rem_val - p[k];
  62. k++;
  63. }
  64.  
  65. // Copy rem_val to next position and increment position
  66. p[k+1] = rem_val;
  67. k++;
  68. }
  69. }
  70.  
  71.  
  72. int main() {
  73. // your code goes here
  74. int n; cin >> n;
  75.  
  76. printAllUniqueParts(n);
  77. cout << "size : " << finalVec.size() << endl;
  78. multiset < int > :: iterator it;
  79.  
  80. int ANS = 0;
  81. vector < int > ansVec;
  82. for (int i = 0; i < finalVec.size(); i++) {
  83. multiset < int > mySet;
  84.  
  85. vector < int > temp = finalVec[i];
  86.  
  87. for (int ii = 0; ii < temp.size(); ii++) {
  88. mySet.insert(temp[ii]);
  89. }
  90.  
  91. int t = n + 4;
  92. int cnt = 0;
  93. while (t --) {
  94. multiset < int > newSet;
  95. newSet.insert(mySet.size());
  96.  
  97. for (it = mySet.begin(); it != mySet.end(); it++) {
  98. if(*it > 1) {
  99. newSet.insert((*it) - 1);
  100. }
  101. }
  102.  
  103. if(newSet == mySet) {
  104. if(cnt > ANS) {
  105. ANS = cnt;
  106. ansVec = temp;
  107. }
  108. break;
  109. }
  110.  
  111. cnt++;
  112. mySet = newSet;
  113. }
  114. }
  115.  
  116. cout << ANS << endl;
  117. for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
  118. cout << endl;
  119.  
  120. return 0;
  121. }/******************************************************************************
  122.  
  123. Welcome to GDB Online.
  124. GDB online is an online compiler and debugger tool for C/C++.
  125. Code, Compile, Run and Debug online from anywhere in world.
  126.  
  127. *******************************************************************************/
  128. #include <iostream>
  129. #include <bits/stdc++.h>
  130. using namespace std;
  131.  
  132. vector < vector < int > > finalVec;
  133.  
  134. void printArray(int p[], int n)
  135. {
  136. vector < int > vec;
  137. for (int i = 0; i < n; i++)
  138. vec.push_back(p[i]);
  139. finalVec.push_back(vec);
  140. return;
  141. }
  142.  
  143. void printAllUniqueParts(int n)
  144. {
  145. int p[n]; // An array to store a partition
  146. int k = 0; // Index of last element in a partition
  147. p[k] = n; // Initialize first partition as number itself
  148.  
  149. // This loop first prints current partition, then generates next
  150. // partition. The loop stops when the current partition has all 1s
  151. while (true)
  152. {
  153. // print current partition
  154. printArray(p, k+1);
  155.  
  156. // Generate next partition
  157.  
  158. // Find the rightmost non-one value in p[]. Also, update the
  159. // rem_val so that we know how much value can be accommodated
  160. int rem_val = 0;
  161. while (k >= 0 && p[k] == 1)
  162. {
  163. rem_val += p[k];
  164. k--;
  165. }
  166.  
  167. // if k < 0, all the values are 1 so there are no more partitions
  168. if (k < 0) return;
  169.  
  170. // Decrease the p[k] found above and adjust the rem_val
  171. p[k]--;
  172. rem_val++;
  173.  
  174.  
  175. // If rem_val is more, then the sorted order is violeted. Divide
  176. // rem_val in differnt values of size p[k] and copy these values at
  177. // different positions after p[k]
  178. while (rem_val > p[k])
  179. {
  180. p[k+1] = p[k];
  181. rem_val = rem_val - p[k];
  182. k++;
  183. }
  184.  
  185. // Copy rem_val to next position and increment position
  186. p[k+1] = rem_val;
  187. k++;
  188. }
  189. }
  190.  
  191.  
  192. int main() {
  193. // your code goes here
  194. int n; cin >> n;
  195.  
  196. printAllUniqueParts(n);
  197. cout << "size : " << finalVec.size() << endl;
  198. multiset < int > :: iterator it;
  199.  
  200. int ANS = 0;
  201. vector < int > ansVec;
  202. for (int i = 0; i < finalVec.size(); i++) {
  203. multiset < int > mySet;
  204.  
  205. vector < int > temp = finalVec[i];
  206.  
  207. for (int ii = 0; ii < temp.size(); ii++) {
  208. mySet.insert(temp[ii]);
  209. }
  210.  
  211. int t = n + 4;
  212. int cnt = 0;
  213. while (t --) {
  214. multiset < int > newSet;
  215. newSet.insert(mySet.size());
  216.  
  217. for (it = mySet.begin(); it != mySet.end(); it++) {
  218. if(*it > 1) {
  219. newSet.insert((*it) - 1);
  220. }
  221. }
  222.  
  223. if(newSet == mySet) {
  224. if(cnt > ANS) {
  225. ANS = cnt;
  226. ansVec = temp;
  227. }
  228. break;
  229. }
  230.  
  231. cnt++;
  232. mySet = newSet;
  233. }
  234. }
  235.  
  236. cout << ANS << endl;
  237. for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
  238. cout << endl;
  239.  
  240. return 0;
  241. }
  242.  
  243.  
  244. /******************************************************************************
  245.  
  246. Welcome to GDB Online.
  247. GDB online is an online compiler and debugger tool for C/C++.
  248. Code, Compile, Run and Debug online from anywhere in world.
  249.  
  250. *******************************************************************************/
  251. #include <iostream>
  252. #include <bits/stdc++.h>
  253. using namespace std;
  254.  
  255. vector < vector < int > > finalVec;
  256.  
  257. void printArray(int p[], int n)
  258. {
  259. vector < int > vec;
  260. for (int i = 0; i < n; i++)
  261. vec.push_back(p[i]);
  262. finalVec.push_back(vec);
  263. return;
  264. }
  265.  
  266. void printAllUniqueParts(int n)
  267. {
  268. int p[n]; // An array to store a partition
  269. int k = 0; // Index of last element in a partition
  270. p[k] = n; // Initialize first partition as number itself
  271.  
  272. // This loop first prints current partition, then generates next
  273. // partition. The loop stops when the current partition has all 1s
  274. while (true)
  275. {
  276. // print current partition
  277. printArray(p, k+1);
  278.  
  279. // Generate next partition
  280.  
  281. // Find the rightmost non-one value in p[]. Also, update the
  282. // rem_val so that we know how much value can be accommodated
  283. int rem_val = 0;
  284. while (k >= 0 && p[k] == 1)
  285. {
  286. rem_val += p[k];
  287. k--;
  288. }
  289.  
  290. // if k < 0, all the values are 1 so there are no more partitions
  291. if (k < 0) return;
  292.  
  293. // Decrease the p[k] found above and adjust the rem_val
  294. p[k]--;
  295. rem_val++;
  296.  
  297.  
  298. // If rem_val is more, then the sorted order is violeted. Divide
  299. // rem_val in differnt values of size p[k] and copy these values at
  300. // different positions after p[k]
  301. while (rem_val > p[k])
  302. {
  303. p[k+1] = p[k];
  304. rem_val = rem_val - p[k];
  305. k++;
  306. }
  307.  
  308. // Copy rem_val to next position and increment position
  309. p[k+1] = rem_val;
  310. k++;
  311. }
  312. }
  313.  
  314.  
  315. int main() {
  316. // your code goes here
  317. int n; cin >> n;
  318.  
  319. printAllUniqueParts(n);
  320. cout << "size : " << finalVec.size() << endl;
  321. multiset < int > :: iterator it;
  322.  
  323. int ANS = 0;
  324. vector < int > ansVec;
  325. for (int i = 0; i < finalVec.size(); i++) {
  326. multiset < int > mySet;
  327.  
  328. vector < int > temp = finalVec[i];
  329.  
  330. for (int ii = 0; ii < temp.size(); ii++) {
  331. mySet.insert(temp[ii]);
  332. }
  333.  
  334. int t = n + 4;
  335. int cnt = 0;
  336. while (t --) {
  337. multiset < int > newSet;
  338. newSet.insert(mySet.size());
  339.  
  340. for (it = mySet.begin(); it != mySet.end(); it++) {
  341. if(*it > 1) {
  342. newSet.insert((*it) - 1);
  343. }
  344. }
  345.  
  346. if(newSet == mySet) {
  347. if(cnt > ANS) {
  348. ANS = cnt;
  349. ansVec = temp;
  350. }
  351. break;
  352. }
  353.  
  354. cnt++;
  355. mySet = newSet;
  356. }
  357. }
  358.  
  359. cout << ANS << endl;
  360. for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
  361. cout << endl;
  362.  
  363. return 0;
  364. }
  365.  
  366.  
  367. /******************************************************************************
  368.  
  369. Welcome to GDB Online.
  370. GDB online is an online compiler and debugger tool for C/C++.
  371. Code, Compile, Run and Debug online from anywhere in world.
  372.  
  373. *******************************************************************************/
  374. #include <iostream>
  375. #include <bits/stdc++.h>
  376. using namespace std;
  377.  
  378. vector < vector < int > > finalVec;
  379.  
  380. void printArray(int p[], int n)
  381. {
  382. vector < int > vec;
  383. for (int i = 0; i < n; i++)
  384. vec.push_back(p[i]);
  385. finalVec.push_back(vec);
  386. return;
  387. }
  388.  
  389. void printAllUniqueParts(int n)
  390. {
  391. int p[n]; // An array to store a partition
  392. int k = 0; // Index of last element in a partition
  393. p[k] = n; // Initialize first partition as number itself
  394.  
  395. // This loop first prints current partition, then generates next
  396. // partition. The loop stops when the current partition has all 1s
  397. while (true)
  398. {
  399. // print current partition
  400. printArray(p, k+1);
  401.  
  402. // Generate next partition
  403.  
  404. // Find the rightmost non-one value in p[]. Also, update the
  405. // rem_val so that we know how much value can be accommodated
  406. int rem_val = 0;
  407. while (k >= 0 && p[k] == 1)
  408. {
  409. rem_val += p[k];
  410. k--;
  411. }
  412.  
  413. // if k < 0, all the values are 1 so there are no more partitions
  414. if (k < 0) return;
  415.  
  416. // Decrease the p[k] found above and adjust the rem_val
  417. p[k]--;
  418. rem_val++;
  419.  
  420.  
  421. // If rem_val is more, then the sorted order is violeted. Divide
  422. // rem_val in differnt values of size p[k] and copy these values at
  423. // different positions after p[k]
  424. while (rem_val > p[k])
  425. {
  426. p[k+1] = p[k];
  427. rem_val = rem_val - p[k];
  428. k++;
  429. }
  430.  
  431. // Copy rem_val to next position and increment position
  432. p[k+1] = rem_val;
  433. k++;
  434. }
  435. }
  436.  
  437.  
  438. int main() {
  439. // your code goes here
  440. int n; cin >> n;
  441.  
  442. printAllUniqueParts(n);
  443. cout << "size : " << finalVec.size() << endl;
  444. multiset < int > :: iterator it;
  445.  
  446. int ANS = 0;
  447. vector < int > ansVec;
  448. for (int i = 0; i < finalVec.size(); i++) {
  449. multiset < int > mySet;
  450.  
  451. vector < int > temp = finalVec[i];
  452.  
  453. for (int ii = 0; ii < temp.size(); ii++) {
  454. mySet.insert(temp[ii]);
  455. }
  456.  
  457. int t = n + 4;
  458. int cnt = 0;
  459. while (t --) {
  460. multiset < int > newSet;
  461. newSet.insert(mySet.size());
  462.  
  463. for (it = mySet.begin(); it != mySet.end(); it++) {
  464. if(*it > 1) {
  465. newSet.insert((*it) - 1);
  466. }
  467. }
  468.  
  469. if(newSet == mySet) {
  470.  
Success #stdin #stdout 0.03s 25480KB
stdin
45
stdout
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C/C++.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

vector < vector < int > > finalVec;

void printArray(int p[], int n)
{
	vector < int > vec;
    for (int i = 0; i < n; i++)
       vec.push_back(p[i]);
    finalVec.push_back(vec);
    return;
}
 
void printAllUniqueParts(int n)
{
    int p[n]; // An array to store a partition
    int k = 0;  // Index of last element in a partition
    p[k] = n;  // Initialize first partition as number itself
 
    // This loop first prints current partition, then generates next
    // partition. The loop stops when the current partition has all 1s
    while (true)
    {
        // print current partition
        printArray(p, k+1);
 
        // Generate next partition
 
        // Find the rightmost non-one value in p[]. Also, update the
        // rem_val so that we know how much value can be accommodated
        int rem_val = 0;
        while (k >= 0 && p[k] == 1)
        {
            rem_val += p[k];
            k--;
        }
 
        // if k < 0, all the values are 1 so there are no more partitions
        if (k < 0)  return;
 
        // Decrease the p[k] found above and adjust the rem_val
        p[k]--;
        rem_val++;
 
 
        // If rem_val is more, then the sorted order is violeted.  Divide
        // rem_val in differnt values of size p[k] and copy these values at
        // different positions after p[k]
        while (rem_val > p[k])
        {
            p[k+1] = p[k];
            rem_val = rem_val - p[k];
            k++;
        }
 
        // Copy rem_val to next position and increment position
        p[k+1] = rem_val;
        k++;
    }
}


int main() {
	// your code goes here
	int n; cin >> n;
	
	printAllUniqueParts(n);
	cout << "size : " << finalVec.size() << endl;
	multiset < int > :: iterator it;

	int ANS = 0;
	vector < int > ansVec;
	for (int i = 0; i < finalVec.size(); i++) {
		multiset < int > mySet;
		
		vector < int > temp = finalVec[i];
		
		for (int ii = 0; ii < temp.size(); ii++) {
			mySet.insert(temp[ii]);
		}
		
		int t = n + 4;
		int cnt = 0;
		while (t --) {
			multiset < int > newSet;
			newSet.insert(mySet.size());
			
			for (it = mySet.begin(); it != mySet.end(); it++) {
				if(*it > 1) {
					newSet.insert((*it) - 1);
				}
			}
			
			if(newSet == mySet) {
				if(cnt > ANS) {
				    ANS = cnt;
				    ansVec = temp;
				}
				break;
			}
			
			cnt++;
			mySet = newSet;
		}
	}
	
	cout << ANS << endl;
	for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
	cout << endl;
	
	return 0;
}/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C/C++.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

vector < vector < int > > finalVec;

void printArray(int p[], int n)
{
	vector < int > vec;
    for (int i = 0; i < n; i++)
       vec.push_back(p[i]);
    finalVec.push_back(vec);
    return;
}
 
void printAllUniqueParts(int n)
{
    int p[n]; // An array to store a partition
    int k = 0;  // Index of last element in a partition
    p[k] = n;  // Initialize first partition as number itself
 
    // This loop first prints current partition, then generates next
    // partition. The loop stops when the current partition has all 1s
    while (true)
    {
        // print current partition
        printArray(p, k+1);
 
        // Generate next partition
 
        // Find the rightmost non-one value in p[]. Also, update the
        // rem_val so that we know how much value can be accommodated
        int rem_val = 0;
        while (k >= 0 && p[k] == 1)
        {
            rem_val += p[k];
            k--;
        }
 
        // if k < 0, all the values are 1 so there are no more partitions
        if (k < 0)  return;
 
        // Decrease the p[k] found above and adjust the rem_val
        p[k]--;
        rem_val++;
 
 
        // If rem_val is more, then the sorted order is violeted.  Divide
        // rem_val in differnt values of size p[k] and copy these values at
        // different positions after p[k]
        while (rem_val > p[k])
        {
            p[k+1] = p[k];
            rem_val = rem_val - p[k];
            k++;
        }
 
        // Copy rem_val to next position and increment position
        p[k+1] = rem_val;
        k++;
    }
}


int main() {
	// your code goes here
	int n; cin >> n;
	
	printAllUniqueParts(n);
	cout << "size : " << finalVec.size() << endl;
	multiset < int > :: iterator it;

	int ANS = 0;
	vector < int > ansVec;
	for (int i = 0; i < finalVec.size(); i++) {
		multiset < int > mySet;
		
		vector < int > temp = finalVec[i];
		
		for (int ii = 0; ii < temp.size(); ii++) {
			mySet.insert(temp[ii]);
		}
		
		int t = n + 4;
		int cnt = 0;
		while (t --) {
			multiset < int > newSet;
			newSet.insert(mySet.size());
			
			for (it = mySet.begin(); it != mySet.end(); it++) {
				if(*it > 1) {
					newSet.insert((*it) - 1);
				}
			}
			
			if(newSet == mySet) {
				if(cnt > ANS) {
				    ANS = cnt;
				    ansVec = temp;
				}
				break;
			}
			
			cnt++;
			mySet = newSet;
		}
	}
	
	cout << ANS << endl;
	for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
	cout << endl;
	
	return 0;
}


    /******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C/C++.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

vector < vector < int > > finalVec;

void printArray(int p[], int n)
{
	vector < int > vec;
    for (int i = 0; i < n; i++)
       vec.push_back(p[i]);
    finalVec.push_back(vec);
    return;
}
 
void printAllUniqueParts(int n)
{
    int p[n]; // An array to store a partition
    int k = 0;  // Index of last element in a partition
    p[k] = n;  // Initialize first partition as number itself
 
    // This loop first prints current partition, then generates next
    // partition. The loop stops when the current partition has all 1s
    while (true)
    {
        // print current partition
        printArray(p, k+1);
 
        // Generate next partition
 
        // Find the rightmost non-one value in p[]. Also, update the
        // rem_val so that we know how much value can be accommodated
        int rem_val = 0;
        while (k >= 0 && p[k] == 1)
        {
            rem_val += p[k];
            k--;
        }
 
        // if k < 0, all the values are 1 so there are no more partitions
        if (k < 0)  return;
 
        // Decrease the p[k] found above and adjust the rem_val
        p[k]--;
        rem_val++;
 
 
        // If rem_val is more, then the sorted order is violeted.  Divide
        // rem_val in differnt values of size p[k] and copy these values at
        // different positions after p[k]
        while (rem_val > p[k])
        {
            p[k+1] = p[k];
            rem_val = rem_val - p[k];
            k++;
        }
 
        // Copy rem_val to next position and increment position
        p[k+1] = rem_val;
        k++;
    }
}


int main() {
	// your code goes here
	int n; cin >> n;
	
	printAllUniqueParts(n);
	cout << "size : " << finalVec.size() << endl;
	multiset < int > :: iterator it;

	int ANS = 0;
	vector < int > ansVec;
	for (int i = 0; i < finalVec.size(); i++) {
		multiset < int > mySet;
		
		vector < int > temp = finalVec[i];
		
		for (int ii = 0; ii < temp.size(); ii++) {
			mySet.insert(temp[ii]);
		}
		
		int t = n + 4;
		int cnt = 0;
		while (t --) {
			multiset < int > newSet;
			newSet.insert(mySet.size());
			
			for (it = mySet.begin(); it != mySet.end(); it++) {
				if(*it > 1) {
					newSet.insert((*it) - 1);
				}
			}
			
			if(newSet == mySet) {
				if(cnt > ANS) {
				    ANS = cnt;
				    ansVec = temp;
				}
				break;
			}
			
			cnt++;
			mySet = newSet;
		}
	}
	
	cout << ANS << endl;
	for (int i = 0; i < ansVec.size(); i++) cout << ansVec[i] << ' ';
	cout << endl;
	
	return 0;
}


    /******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C/C++.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

vector < vector < int > > finalVec;

void printArray(int p[], int n)
{
	vector < int > vec;
    for (int i = 0; i < n; i++)
       vec.push_back(p[i]);
    finalVec.push_back(vec);
    return;
}
 
void printAllUniqueParts(int n)
{
    int p[n]; // An array to store a partition
    int k = 0;  // Index of last element in a partition
    p[k] = n;  // Initialize first partition as number itself
 
    // This loop first prints current partition, then generates next
    // partition. The loop stops when the current partition has all 1s
    while (true)
    {
        // print current partition
        printArray(p, k+1);
 
        // Generate next partition
 
        // Find the rightmost non-one value in p[]. Also, update the
        // rem_val so that we know how much value can be accommodated
        int rem_val = 0;
        while (k >= 0 && p[k] == 1)
        {
            rem_val += p[k];
            k--;
        }
 
        // if k < 0, all the values are 1 so there are no more partitions
        if (k < 0)  return;
 
        // Decrease the p[k] found above and adjust the rem_val
        p[k]--;
        rem_val++;
 
 
        // If rem_val is more, then the sorted order is violeted.  Divide
        // rem_val in differnt values of size p[k] and copy these values at
        // different positions after p[k]
        while (rem_val > p[k])
        {
            p[k+1] = p[k];
            rem_val = rem_val - p[k];
            k++;
        }
 
        // Copy rem_val to next position and increment position
        p[k+1] = rem_val;
        k++;
    }
}


int main() {
	// your code goes here
	int n; cin >> n;
	
	printAllUniqueParts(n);
	cout << "size : " << finalVec.size() << endl;
	multiset < int > :: iterator it;

	int ANS = 0;
	vector < int > ansVec;
	for (int i = 0; i < finalVec.size(); i++) {
		multiset < int > mySet;
		
		vector < int > temp = finalVec[i];
		
		for (int ii = 0; ii < temp.size(); ii++) {
			mySet.insert(temp[ii]);
		}
		
		int t = n + 4;
		int cnt = 0;
		while (t --) {
			multiset < int > newSet;
			newSet.insert(mySet.size());
			
			for (it = mySet.begin(); it != mySet.end(); it++) {
				if(*it > 1) {
					newSet.insert((*it) - 1);
				}
			}
			
			if(newSet == mySet) {