D. Triangle Coloring
https://codeforces.com/contest/1795/problem/D
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=3e5+10,mod=998244353;
int n;
ll qmi(ll a,ll k){
ll res=1;
while(k){
if(k&1) res=res*a%mod;
k>>=1;
a=a*a%mod;
}
return res;
}
bool fact(int a,int b,int c){
return a==b&&a<c&&b<c;
}
int main(){
ll res=1;
cin>>n;
ll k=1;
for(int i=1;i<=n;i+=3){
int x,y,z;
cin>>x>>y>>z;
if(x==y&&x==z) k=k*3%mod;
else if(fact(x,y,z)||fact(x,z,y)||fact(y,z,x)) k=k*2%mod;
}
for(int i=n/3,j=1;i>n/6;i--,j++){
res=res*i%mod;
res=res*qmi(j,mod-2)%mod;
}
res=res*k%mod;
cout<<res<<endl;
}
/*
就是每三个点一组,给所有数字染色,颜色只有红蓝,且一半染红一半染蓝
要想要使得结果最大
每个三原组有两种染法,红蓝蓝或者蓝红红
我们一共n/3个组,根据对称可得,n/6个得染红蓝蓝
另外有些特殊情况
例如当三个边权都一样时,就有三种情况
当两个边权一样且都是小边权时有两种情况
*/
D. Triangle Coloring的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- 【leetcode】Triangle (#120)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
随机推荐
- 电脑本地安装不同版本MySQL
本地已经安装了mysql5.7版本,想测试mysql8版本的用法,想在一台电脑同时配置不同版本的mysql在不同端口号,看起来简单,实现起来其实挺多坑的,总结下实战经验和大家分享下 一.下载安装 下载 ...
- 基于ROS的串口底层写法
serial_device.cpp #include "serial_device.h" namespace roborts_sdk { SerialDevice::SerialD ...
- 关于Promise.all()的理解
本篇笔记是抄的别人的,目的只是为了日后有用到时有个参考,原文地址是https://www.jianshu.com/p/7e60fc1be1b2 一.Pomise.all的使用 Promise.all可 ...
- LG P3809 【模板】后缀排序
贴模板 注意:\(\text{id}\) 表示第二关键字排序后(其实无需排序,利用上轮的 \(\text{sa}\) 值即可)相应的第一关键字的位置 计数排序为了稳定性最后确定位置时要倒着开始 复制的 ...
- C#/JS 压缩到指定大小的图片 (内存不足问题修改)
//因为浏览器安全问题,无法获取上传图片地址,需要先存一遍然后再获取地址作参数上传 var des = CompressImage(@"C:\Users\PC\Pictures\测试\165 ...
- swiper弹出窗口居中效果css
position: absolute; width: 800px; left: 50%; top: 50%; transform: translate(-50%, -50%);
- js的map、filter的用法
filter() 创建新数组,新数组放指定数组中符合条件的元素,满足条件的留下,是对原数组的过滤. map() 返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值,是对原数组的加工,映 ...
- sys.argv的用法
一.Python sys 模块 "sys" 是 "system",是一个系统模块,该模块提供了一些接口,用户访问python解释器自身使用和维护的变量,同时模块 ...
- Mars3D入门示例
1. 引言 Mars3D是基于Cesium的Web端的三维GIS库,对Cesium做了进一步封装和扩展 Mars3D官网:Mars3D三维可视化平台 | 火星科技 Mars3D开发手册:开发教程 - ...
- 基于Python的OpenGL 05 之坐标系统
1. 引言 本文基于Python语言,描述OpenGL的坐标系统 前置知识可参考: 基于Python的OpenGL 04 之变换 - 当时明月在曾照彩云归 - 博客园 (cnblogs.com) 笔者 ...