Dan robocontest javoblari



Yüklə 0,58 Mb.
səhifə7/7
tarix07.01.2024
ölçüsü0,58 Mb.
#204426
1   2   3   4   5   6   7
2 5411487045807781686

94-masala
#include
using namespace std;
#define ll long long
#define int long long
signed main(){
int n, m,k;
cin >> n;
m=n;
int matrix[n][n];
for(int i = 0; ifor(int j = 0; jcin >> matrix[i][j];
}
}
int sumRow[n], sumCol[n];
memset(sumRow, 0, sizeof(sumRow));
memset(sumCol, 0, sizeof(sumCol));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
sumRow[i] += matrix[i][j];
sumCol[j] += matrix[i][j];
}
int maxSum = 0;
for (int i = 0; i < n; ++i) {
maxSum = max(maxSum, sumRow[i]);
maxSum = max(maxSum, sumCol[i]);
}
ll count = 0;
for (int i = 0, j = 0; i < n && j < n;) {
int diff
= min(maxSum - sumRow[i], maxSum - sumCol[j]);
matrix[i][j] += diff;
sumRow[i] += diff;
sumCol[j] += diff;
count += diff;
if (sumRow[i] == maxSum)
++i;
if (sumCol[j] == maxSum)
++j;
}
cout << count;
}

95-masala
#include
#define int long long
using namespace std;

const int V = ((1 << 10) - 1);


void P(vector v, map

int>& freq)

{

for (int i = 0; i < v.size(); i++) {



int mask = 0;
unordered_set T;

for (int j = 0; j < v[i].size(); j++)

T.insert(v[i][j] - '0');
for (auto it = T.begin(); it != T.end(); it++) {

int digit = (*it);

mask += (1 << digit);

}
freq[mask]++;

}

}

int S(map freq)



{

int ans = 0;


for (int i = 1; i <= 1023; i++) {

for (int j = 1; j <= 1023; j++) {


if ((i | j) == V) {

if (i == j)

ans += (freq[i] * (freq[i] - 1));

else


ans += (freq[i] * freq[j]);

}

}



}
return ans/2;

}


int C(vector v)

{
map freq;

P(v, freq);
return S(freq);

}
main()

{

int n;


string str;

cin>>n;


vector v;

for(int i=0;i

cin>>str;

v.push_back(str);

}

cout << C(v) << endl;



return 0;

}

96-masala


#include


#include
#include
#include
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(VA_ARGS, _repl, _rep)(VA_ARGS)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, VA_ARGS)
void _dbg(string){cout<template void _dbg(string s,H h,T... t){int l=s.find(',');cout<template ostream& operator<<(ostream &o, const pair &p){o<<"("<
template ostream& operator<<(ostream &o, const vector &v){o<<"[";for(T t:v){o<#define INF 1120000000
#define MOD 1000000007
#define long long long
template
class BIT
{
private:
vector bit;
int n;
public:
BIT(int _n) : n(_n)
{
bit = vector(n+1, 0);
}
void add(int v, T a)
{
for(int x=v+1; x<=n; x += x&(-x)) bit[x] += a;
}
T sum(int v)
{
T ret=0;
for(int x=v+1; x>0; x -= x&(-x)) ret += bit[x];
return ret;
}
};
int a[300005];
bool appear[300005];
long fact[300005];
int main()
{
int n;
scanf("%d", &n);
rep(i,n) scanf("%d", a+i);
fill(appear, appear+n+1, false);
rep(i,n) appear[a[i]] = true;
vector b;
rep(i,1,n+1) if(!appear[i]) b.pb(i);
fact[0] = 1;
rep(i,n) fact[i+1] = (i+1)*fact[i] %MOD;
long m = b.size();
long sumb = 0;
for(auto x : b) sumb += x-1;
sumb %= MOD;
BIT bit(n+1);
long ans = fact[m];
long k = 0;
long pre = 0;
rep(i,n)
{
if(a[i]==0)
{
long tmp = sumb * fact[m-1] %MOD
- pre * fact[m-1] %MOD
- ((m>=2) ? (m*(m-1)/2 %MOD * fact[m-2] %MOD * k %MOD) : (0));

ans = (ans + tmp*fact[n-i-1]) %MOD;


k++;
}
else
{
long tmp = (a[i]-1) * fact[m] %MOD
- bit.sum(a[i]) * fact[m] %MOD
- ((m>=1) ? ((long)(lower_bound(all(b), a[i]) - b.begin()) * k %MOD * fact[m-1] %MOD) : (0));
ans = (ans + tmp*fact[n-i-1]) %MOD;
bit.add(a[i], 1);
pre = (pre + b.end() - lower_bound(all(b), a[i])) %MOD;
}
}
ans %= MOD;
if(ans < 0) ans += MOD;
cout << ans << '\n';
return 0;
}

97-masala
#include

using namespace std;

int main() {
long long a, b;
cin >> a >> b;

long long i = 1;


while (true) {
if ((a & i) == (b & i)) {
cout << i << endl;
break;
}
i = i * 2;
}

return 0;


}


98-masala
#include

using namespace std;

int main() {
long long n;
cin >> n;

long long k = 0;


while (n > 1) {
if (n % 3 == 0) {
n = n / 3;
k += 1;
} else if (n % 3 == 1 && n != 1) {
n = 2 * n + 1;
k += 1;
} else {
n = 2 * n - 1;
k += 1;
}
}

cout << k << endl;

return 0;
}
99-masala
#include
#include

using namespace std;

int main() {
long long n;
cin >> n;
long long a = 0;

if (n == 2 || n == 3) {


cout << 2 << endl;
} else if (n == 1) {
cout << 1 << endl;
} else {
long long i = 1;
while (i <= sqrt(n + 1)) {
if ((n + 1) % i == 0) {
a += 1;
}
i += 1;
}

if (a >= 2) {


cout << 0 << endl;
} else {
cout << n << endl;
}
}

return 0;


}

100-masala
#include

using namespace std;

string uzinlik(long long x1, long long x2, long long x4, long long y1, long long y2, long long y4) {
long long a = ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));
long long b = ((x1 - x4) * (x1 - x4)) + ((y1 - y4) * (y1 - y4));

if (a == b) {


return "YES";
} else {
return "NO";
}
}

int main() {


int t;
cin >> t;

for (int i = 0; i < t; ++i) {


long long x1, x2, x3, x4, y1, y2, y3, y4;
cin >> x1 >> x2 >> x3 >> x4;
cin >> y1 >> y2 >> y3 >> y4;

cout << uzinlik(x1, x2, x4, y1, y2, y4) << endl;


}

return 0;


}

Yüklə 0,58 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin