- 1
$result = $this->CachedRequest(600, $sirenaXml->Write(true) . ' ', $rxml); // Никто никогда не поверит, зачем нужен пробел. ЧТОБЫ ВСЕ РАБОТАЛО! Магия.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+29
$result = $this->CachedRequest(600, $sirenaXml->Write(true) . ' ', $rxml); // Никто никогда не поверит, зачем нужен пробел. ЧТОБЫ ВСЕ РАБОТАЛО! Магия.
запрос в систему бронирования авиабилетов
+29
bool MyProc::CompareModule(int *operand1, int *operand2, int n) {
for (int i = 1; i < n; i++) {
if (operand1[i] != operand2[i]) {
if (operand1[i] < operand2[i])
return false;
else
return true;
};
};
return true;
};
−42.8
procedure TForm1.fritb(ie:longint;var fr0:extended);
begin
v1:=0;
for nsf:=1 to 5 do
begin
kl11:=0;kl12:=0;kl22:=0;
for k:=1 to km[nsf] do
begin
if (cm^[ie]=cm^[nm^[(ie-1)*kms[ksf+1]+kms[nsf]+k]])and (cm^[ie]=1)
then kl11:=kl11+1;
if (cm^[ie]=cm^[nm^[(ie-1)*kms[ksf+1]+kms[nsf]+k]])and (cm^[ie]=2)
then kl22:=kl22+1;
if (cm^[ie]<>cm^[nm^[(ie-1)*kms[ksf+1]+kms[nsf]+k]])and(cm^[nm^[(ie-1)*kms[ksf+1]+kms[nsf]+k]]<>0)and (cm^[ie]<>0)
then kl12:=kl12+1;
end;
fr0:=fr0+kl11*(p11[1,nsf])+kl22*p11[2,nsf]+kl12*p11[3,nsf];
v1:=v1+kl11*(f11[1,nsf])+kl22*f11[2,nsf]+kl12*f11[3,nsf];
end;
fr0:=fr0-sqrt(abs(v1));
end;
процеДуро
−50
contents = contents.replaceAll("\\<(\\w+)\\>", "<CT_$1>\n");
contents = contents.replaceAll("\\<(\\w+)(\\s\\w+)=\\"(\\w+)\\"\\>", "<CT_$1$2=\"$3\">\n");
contents = contents.replaceAll("\\<(\\w+)(\\s\\w+)=\\'(\\w+)\\'\\>", "<CT_$1$2='$3'>\n");
contents = contents.replaceAll("\\</(\\w+)\\>", "\n</CT_$1>\n");
преобразуем эскейпнутые тэги в обычные
+30
private static string identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc =
new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
return result;
}
0
#include <stdio.h>
#define int long long
#define mx 1000000
signed main(void) {
int n;
scanf("%lld", &n);
if (n > mx) {
printf("-1");
return 0;
}
int x = n;
int l = n; // чашка с товаром
int r = 0; // другая чашка
int w = 1;
int c = 0;
while (x != 0) {
if (x % 3 == 0) {
x /= 3;
}
else if (x % 3 == 1) {
r += w;
c++;
x /= 3;
}
else { // x % 3 == 2
l += w;
c++;
x = (x + 1) / 3;
}
w *= 3;
}
if (l > mx || r > mx)
printf("-1");
else
printf("%lld", c);
return 0;
}
#define int long long
int x = n;
int l = n; // чашка с товаром
int r = 0; // другая чашка
int w = 1;
int c = 0;
фортепиано
0
// macro.h
#undef IF_NOT_HEADER
#undef IF_HEADER
#undef FUNC_BODY
#ifndef IS_HEADER
#define IF_NOT_HEADER(...) __VA_ARGS__
#define IF_HEADER(...)
#define FUNC_BODY(...) {__VA_ARGS__}
#else
#define IF_NOT_HEADER(...)
#define IF_HEADER(...) __VA_ARGS__
#define FUNC_BODY(...) ;
#endif
// src.c
#include "macro.h"
IF_HEADER(extern) int var IF_NOT_HEADER(= 42);
IF_HEADER(extern) int f(int x) FUNC_BODY(return var;)
// header.h
#ifndef IS_HEADER
#define IS_HEADER
#include "src.c"
#undef IS_HEADER
#else
#include "src.c"
#endif
0
function minifyJSCSS(&$content) {
global $USER;
global $APPLICATION;
if (is_object($USER) && $USER->IsAdmin()) return;
preg_match_all('/<link.+?href="\/bitrix\/cache[^>]+>/',$content, $result);
foreach ($result[0] as $css)
{
preg_match('/(href)=("[^"]*")/i',$css, $file);
$orig_file = reset(explode('?',str_replace('"','',$file[2])));
if (stristr($orig_file,'.css') === false)
continue;
$min_file = str_replace('.css','.min.css',$orig_file);
if (!file_exists($min_file))
{
$compress = file_get_contents($_SERVER["DOCUMENT_ROOT"].$orig_file);
$compress = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $compress);
$compress = str_replace(array("\r\n", "\r", "\n", "\t", " ", " ", " "), "", $compress);
file_put_contents($_SERVER["DOCUMENT_ROOT"].$min_file, $compress);
}
$content = str_replace($orig_file,$min_file,$content);
}
if (strpos($_SERVER['HTTP_USER_AGENT'],'Lighthouse'))
{
preg_match_all('/<script.+?src="\/bitrix\/cache[^>]+>/',$content, $result);
foreach ($result[0] as $js)
{
preg_match('/(src)=("[^"]*")/i',$js, $file);
$orig_file = reset(explode('?',str_replace('"','',$file[2])));
$orig_file = $orig_file;
$min_file = str_replace('.js','.min.js',$orig_file);
if (!file_exists($_SERVER["DOCUMENT_ROOT"].$min_file))
{
$url = 'https://javascript-minifier.com/raw';
$js = file_get_contents($_SERVER["DOCUMENT_ROOT"].$orig_file);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
CURLOPT_POSTFIELDS => http_build_query([ "input" => $js ])
]);
$minified = curl_exec($ch);
curl_close($ch);
file_put_contents($_SERVER["DOCUMENT_ROOT"].$min_file,$minified);
$gzdata = gzencode($minified, 9);
file_put_contents($_SERVER["DOCUMENT_ROOT"].$min_file.'.gz', $gzdata);
}
$content = str_replace($orig_file,$min_file,$content);
}
}
}
Жулики-говнокодеры пытались улучшить оценку производительности
0
Counting Sort - O(n + k)
Counting Sort O(n + k) O(n + k) O(n + k) O(k) ✅ Маленький диапазон значений
def counting_sort(nums):
count = defaultdict(int)
minVal, maxVal = min(nums), max(nums)
for val in nums:
count[val] += 1
index = 0
for val in range(minVal, maxVal + 1):
while count[val] > 0:
nums[index] = val
index += 1
count[val] -= 1
from collections import defaultdict
def stable_counting_sort(nums):
if not nums:
return nums
# 1. Считаем сколько раз встретилось каждое число
count = defaultdict(int)
for val in nums:
count[val] += 1
# 2. Получаем отсортированные ключи
sorted_keys = sorted(count.keys())
# 3. Считаем префиксные суммы (позиции для стабильности)
positions = {}
total = 0
for key in sorted_keys:
positions[key] = total
total += count[key]
# 4. Создаём массив результата
output = [0] * len(nums)
for val in nums:
index = positions[val]
output[index] = val
positions[val] += 1 # увеличиваем позицию для следующего одинакового элемента
return output
0
cin >> N >> L >> T;
total = 0;
for (int i = 0; i < N; i++) {
cin >> S[i] >> H[i] >> P[i];
total += H[i] * P[i];
}
fix_order();
for (int ind = 0; ind < N; ind++) {
int len = ind + 1;
set<pair<long long, int>> events, comps;
vector<long long> sum_hp(len);
copy(H, H + len, sum_hp.begin());
sum_hp[ind] = 0;
vector<int> ord(len);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return S[i] < S[j];
});
comps.emplace(T, -1);
for (int i = 0; i < len; i++) {
int j = i + 1;
while (j < len && S[ord[i]] == S[ord[j]]) {
sum_hp[ord[i]] += sum_hp[ord[j]];
++j;
}
comps.emplace(S[ord[i]], ord[i]);
i = j - 1;
}
for (auto it = comps.begin(); next(it) != comps.end(); ++it) {
long long dist = next(it)->first - it->first;
int idx = it->second;
if (sum_hp[idx] > 0) {
events.emplace((dist + sum_hp[idx] - 1) / sum_hp[idx], idx);
}
}
vector<bool> visited(len);
vector<bool> added(len);
long long good_sum = 0, last_time = 0, govno = T, rakom_bokom = 0;
for (auto [spawn, i] : comps) {
if (spawn >= S[ind] && i != -1) {
good_sum += sum_hp[i];
added[i] = true;
}
}
auto Upd = [&](long long time) -> void {
long long F = govno - S[ind] - rakom_bokom;
if (F <= 0) {
return;
}
long long r1 = clamp(F / (H[ind] + good_sum) + 1, last_time, time);
long long r2 = good_sum == 0 ? time : clamp(F / good_sum + 1, last_time, time);
dp_diff_i[last_time] += H[ind] * P[ind];
dp_diff_i[r1] -= H[ind] * P[ind];
dp_diff[r1] += F * P[ind];
dp_diff[r2] -= F * P[ind];
dp_diff_i[r1] -= good_sum * P[ind];
dp_diff_i[r2] += good_sum * P[ind];
last_time = time;
};
vector<bool> skip(len), finished(len);
while (!events.empty()) {
auto [time, i] = *events.begin();
events.erase(events.begin());
if (time > L) {
break;
}
if (skip[i] || sum_hp[i] == 0) {
continue;
}
Upd(time);
auto it = comps.upper_bound({S[i], INT_MAX});
if (it->second == -1 || finished[it->second]) {
good_sum -= sum_hp[i];
finished[i] = true;
govno = S[i];
continue;
}
if (!added[i] && it->second + sum_hp[i] * time >= S[ind]) {
added[i] = true;
good_sum += sum_hp[i];
rakom_bokom += S[i] - S[ind];
}
sum_hp[i] += sum_hp[it->second];
skip[it->second] = true;
long long next_pos = next(it)->first;
comps.erase(it);
events.emplace(time + (next_pos - S[i] - sum_hp[i] * time + sum_hp[i] - 1) / sum_hp[i], i);
}
Upd(L + 1);
}
long long cur_diff = 0, cur_diff_i = 0;
for (int i = 0; i <= L; i++) {
cur_diff += dp_diff[i];
cur_diff_i += dp_diff_i[i];
dp[i] = cur_diff + cur_diff_i * i;
}
олимпиадное говно