#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <string> #include <unordered_map> #include <map> #include <set> #include <vector> using namespace std; typedef long long int lld; int n; lld A[104]; // std::unordered_map<lld,lld> S[2]; std::vector<int> V[2]; std::unordered_map<lld,lld> C; // std::unordered_set<string> E[2]; /* pair<string,lld> dat(lld& a, lld& b, lld& c) { std::vector<lld> v={a,b,c}; std::set<lld> tmpS={}; for (lld vv : v) { tmpS.insert(vv); } string sk=""; for (lld vv : tmpS) { sk+=to_string(vv)+"-"; } return {sk,tmpS.size()}; }*/ int ss(lld& a, lld& b, lld& c, int d) { if (d) { return a*(b+c); } return a*b+c; } void in_V(lld a, lld b, lld c, int d, int si) { // pair<string,lld> dd = dat(a,b,c); //if (E[si].find(dd.first)==E[si].end()) { //E[si].insert(dd.first); //printf("-> %lld %lld %lld: %d\n",a,b,c,d); /* std::set<lld> poss={}; poss.insert(ss(a,b,c,d)); poss.insert(ss(a,c,b,d)); poss.insert(ss(b,a,c,d)); poss.insert(ss(b,c,a,d)); poss.insert(ss(c,a,b,d)); poss.insert(ss(c,b,a,d)); for (lld curss : poss) { S[si][curss]++; }*/ // guessing game! if (d) { if (a) { V[si].push_back(ss(a,b,c,d)); V[si].push_back(ss(a,c,b,d)); // S[si][ss(a,b,c,d)]++; // S[si][ss(a,c,b,d)]++; } if (b) { V[si].push_back(ss(b,a,c,d)); V[si].push_back(ss(b,c,a,d)); // S[si][ss(b,a,c,d)]++; // S[si][ss(b,c,a,d)]++; } if (c) { V[si].push_back(ss(c,a,b,d)); V[si].push_back(ss(c,b,a,d)); } } else { V[si].push_back(ss(a,b,c,d)); V[si].push_back(ss(a,c,b,d)); V[si].push_back(ss(b,a,c,d)); V[si].push_back(ss(b,c,a,d)); V[si].push_back(ss(c,a,b,d)); V[si].push_back(ss(c,b,a,d)); /* S[si][ss(a,b,c,d)]++; S[si][ss(a,c,b,d)]++; S[si][ss(b,a,c,d)]++; S[si][ss(b,c,a,d)]++; S[si][ss(c,a,b,d)]++; S[si][ss(c,b,a,d)]++; */ } // many different meaning, trying to guess the approach. /* switch (dd.second) { case(1): { S[si][ss(a,b,c,d)]++; break; } case(2): { std::vector<lld> v={a,b,c}; std::sort(v.begin(),v.end()); if (v[0]==v[1]) { a=v[0];b=v[1];c=v[2]; } else { a=v[1];b=v[2];c=v[0]; } S[si][ss(a,b,c,d)]++; S[si][ss(a,c,b,d)]++; S[si][ss(c,a,b,d)]++; break; } case(3): { S[si][ss(a,b,c,d)]++; S[si][ss(a,c,b,d)]++; S[si][ss(b,a,c,d)]++; S[si][ss(b,c,a,d)]++; S[si][ss(c,a,b,d)]++; S[si][ss(c,b,a,d)]++; break; } default: { break; } }*/ //} return; } int main() { scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%lld",&A[i]); } for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { for (int k=0; k<n; k++) { V[0].push_back(ss(A[i],A[j],A[k],0)); if (A[i]!=0) { V[1].push_back(ss(A[i],A[j],A[k],1)); } //in_V(A[i],A[j],A[k],1,1); //in_V(A[i],A[j],A[k],0,0); } } } C={}; lld res=0ll; std::sort(V[0].begin(),V[0].end()); std::sort(V[1].begin(),V[1].end()); for (int& vv : V[0]) { if (C.count(vv)==0) { int uu=std::distance(V[1].begin(),std::upper_bound(V[1].begin(),V[1].end(),vv)); int ll=std::distance(V[1].begin(),std::lower_bound(V[1].begin(),V[1].end(),vv)); C[vv]=uu-ll; } res+=(lld)C[vv]; } printf("%lld",res); return 0; } /* 2.38 seconds this time, troll. 1.93 seconds, accepted after minor changes for size of vector array, exact same idea. Let's try one more time. time limit exceeded for this. the idea is very simple yet requires excessive "guessing" on the ordering of numbers but it's just not fast enough ha ha ha ha... */
Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++
and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}